-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation on migrations with multiple projects is unclear #933
Comments
Seconded. Number 3 says Move the migrations and model snapshot files to the class library. Number 4 says Configure the migrations assembly. |
With the help of https://github.com/bricelam/Sample-SplitMigrations I could create a setup which allows to use the same migrations for both my App and my unit tests. It is what I wanted to accomplish when reading the documentation, hopefully this usecase helps someone else; and possibly when enhancing the documentation. Setup:
Usecase: How to prepare:
Now you can
Unit Test example code:
|
... but how to migrate with continuous delivery (like in Azure DevOps)? Deployment tasks typically access build artifacts only. Is there a way to run migrations after build? Or do I need to include source in the artifacts and add dotnet SDK to task environment? Is |
You can run any commands in the post deployment script of your release task. I did not need any special configuration (I am using a release pipeline which Visual Studio setup automatically). I do not know if its completely equivalent, but I've used both and did not run into any issues. |
Azure DevOps is a bit different. The "release" pipelines begin with artifacts (from builds) only. Another complication is I'm doing a self-contained deployment (no dotnet core runtime on target machines), I essentially only have access to the compiled binaries (.exe and dll) at deploy time. I ended up adding a stage in my pipeline to call the .exe with a command line argument which triggers context.Database.Migrate(). I'm hoping this has same behavior as |
The documentation is too brief, but I've managed to get it working as follows (whilst also adhering to Onion Architecture):
|
Note: several of the duplicate issues have scenarios/gotchas that we should make sure are covered. |
Guys, I still can't figure out how to add migration to such projects like this one in example https://github.com/dotnet/EntityFramework.Docs/tree/main/samples/core/Schemas/ThreeProjectMigrations ?
I already configured startup.cs with:
Just FYI. |
@VerdonTrigance These two things contradict each other:
|
@bricelam but that is only way I make |
It also seems that TwoProjectMigrations sample is not working — at least, not with This could be worked around with setting |
I think this issue #3152 should re-opened, trying to follow the docs which seem to assume most people are running migrations from CLI command line, does not work for the case of context.Database.Migrate. I have done the separate solutions for our different providers and generated the migrations, only to find context.Migrate.Database cannot find the migrations assembly specified in UseMyProvider ( connStr, x => x.MigrationsAssembly ( "MyProviderMigrations" ). |
talking about a tutorial!!!!! you got it man a step by step for beginners your awesome.... i get an error however while running dotnet ef migrations add initial create with code , could not find librairy app.migration , i tried to add it but still not working. |
Hello, I simply documented the steps that took me to a working solution. Maybe it can help until the documentation is suitable for a beginner like me 😉. |
I agree with the other commenter that this article is not very clear. I'd go so far as to say it is pretty badly written.
The code snippet refers to "MyApp.Migrations". What is MyApp? Is that the name of the original web project (with dbcontext), or is it the new class library?
And what does "startup assembly" refer to? The web app or the class library?
The fix for removing the circular reference does not work. If each project is supposed to reference the other, then we should expect a circular reference, which is what we get. The suggested fix does not appear to work (not sure if I am doing it wrong), and since no part of the article explains the reasoning behind any of the steps, one cannot even troubleshoot if these steps didn't work.
It would also help to include a few screenshots of how to add a new class library, how to add a reference, and where one can find the XML file where the circular reference fix is supposed to go. After all, we are not all Visual Studio experts.
I have been unable to successfully put migrations in a separate assembly, so I would say this article has not helped me at all.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: