-
Notifications
You must be signed in to change notification settings - Fork 3.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
dnx ef database update
not modifying database
#4188
Comments
Ok, I cloned the EF repo and found out that the problem was on https://github.com/aspnet/EntityFramework/blob/dev/src/EntityFramework.Relational/Migrations/Internal/MigrationsAssembly.cs#L33 It's reading the Assembly from the Context (which in my case is another referenced project) but the Migrations file was created running the command on the project that actually uses the Context (the one with the Startup.cs file). On that same line, it's trying to parse some Option that might define the Assembly, but I found no commandline options for that on the |
As a workaround, I copied all the Migration files created on my Api project to the Context project and adjusted the namespace on them. The |
This experience may have been improved by #4098 |
@bricelam awesome :) In this scenario, the Migration files should be inside the DbContext project, but that leads to a DbContext project needing Mvc dependencies to have a Startup.cs file, which doesn't sound too "clean". From your reference I understand that I'd get a Throw if I ran the migration command on the Web/Api project once that gets merged and part of a released version, is that correct? |
The root problem was that you could add migrations to a project that wasn't configured as your migrations project. Then when you try to apply those migrations they can't be found. This stops you from doing that and instructs you either to add them to a different project or configure you migrations project to be the one you're trying to add them to. |
Ultimately, your Startup, DbContext & Migrations classes can each be in their own project. You just need to configure the migrations assembly, invoke the command on the startup project specifying the target project. |
I ran into the same Problem. How can I configure the migrations assembly? Edit: I only managed to specify the target project for the add command with If I then run the |
I've been beating my head against the keyboard for the past couple hours over this same problem and then finally came across this issue. I got it working thanks @bricelam's last comment. So given two separate projects, say a web project and a class library, if you have a separate context in each an you run commands from the web project (the one with the Startup.cs)...
Will put the migration in the ClassLibrary project.
Will apply the migration to the database. |
Awesome @dougludlow I was trying to achieve it but couldn't find the correct I'll close this issue now. |
@dougludlow I've been looking for this for hours now. Thank you so much! |
👍 |
Hi, My Migration class are not creating in my class library project. all the migrations codes are moving to wrap folder --EF Command Line Output
So Ones I copied the Migration Folder from wrap folder to ClassLibrary Project then it works fine What's i'm doing wrong ? |
We are using EntityFramework.MicrosoftSqlServer version 7.0.0-rc1-final. Running on dnx 1.0.0-rc1-final (Windows).
We followed the procedure described on https://ef.readthedocs.org/en/latest/getting-started/aspnet5/new-db.html
When we run
dnx ef migrations add
we can see the files being created in the Migrations folder. Upon inspecting them, we can see that it's indeed creating our tables for our database (Azure SQL DB).But if I run
dnx ef migrations list
we see no migrations listed.So when we run
dnx ef database update
we only get a Done message but the database contains none of our tables and only an empty __EFMigrationsHistory.Tried it with a local db on a SQL Express but the same thing happened.
Our DBContext is on a Class Library project being referenced but all the namespacing of the generated migration files seem ok.
Any way this can be debugged?
The text was updated successfully, but these errors were encountered: