Skip to content
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

Running dnx ef update database creates empty db #3981

Closed
lasrol opened this issue Dec 4, 2015 · 16 comments
Closed

Running dnx ef update database creates empty db #3981

lasrol opened this issue Dec 4, 2015 · 16 comments

Comments

@lasrol
Copy link

lasrol commented Dec 4, 2015

I currently have an issue where i create a migration with dnx ef migrations add init. It creates the migrations as expected, but when i try to run dnx ef database update i just creates an empty database with the ef migrations history table.

I have reproduced this issue in this repository.

I am running db update from EmptyDB.Migrations project. Not sure if my way of doing it is wrong, but i guess it should give me some kind of error of its wrong.

@n0rwin
Copy link

n0rwin commented Dec 6, 2015

I'm having the same issue.
Migration creation seems to work fine, but running 'dnx ef database update' just creates the migration history table.
When I run 'dnx. ef migrations list' it says 'No migrations were found'

@techcap
Copy link

techcap commented Dec 7, 2015

I have the same issue, too.
If I move ApplicationDbContext and ApplicationUser to other class library, it says 'No migrations were found', as megust42 mentioned.

@techcap
Copy link

techcap commented Dec 7, 2015

@lasrol
Copy link
Author

lasrol commented Dec 7, 2015

It is not quite the samme issue. I have a custom startup.cs file in my migration project, that refrences the data project. This actually are creating the migration files as expected, but for some reason it does not update my database. Just creates a empty db.

@techcap
Copy link

techcap commented Dec 8, 2015

Did you do on EmptyDB.Migrations project folder with the command?

dnx ef migrations add Init --targetProject EmptyDB.Data

@lasrol
Copy link
Author

lasrol commented Dec 8, 2015

As i write above in first post and second post, and you can see in the repository provided, I dont have a problem generating the migration.

The issue occurs when i try to update the database, list migrations or generate sql script. It cannot find any of my MIgrations previously created. I run the command from EmptyDB.Migration project, but that should(if i am not misunderstanding some thing) work since i have reference to data project and i have the startup file created in that project.

@techcap
Copy link

techcap commented Dec 8, 2015

The migration script should be generated in the project which has DbContext, EmptyDB.Data, not in EmptyDB.Migrations or EmptyDB. Without --targetProject option, migration scripts are generated in the project in which dnx runs, and it will generate empty db.

@n0rwin
Copy link

n0rwin commented Dec 8, 2015

But shouldn't the question be, why you have to put your migrations in the same project as the DbContext?
Personally I don't see any reason to put your migrations in a separate project, but I'm sure people can come up with one.
And being able to generate migrations in a project of your choice, but then being unable to run the DB updates if there is no DbContext in the same project as the migrations is a bit confusing.

If this is the expected behaviour I would at least expect an Error/Info message when I generate migrations in a project with no DbContext, or when I try to run a DB update with Migrations and a DbContext in separate projects.

@lasrol
Copy link
Author

lasrol commented Dec 8, 2015

Yes that's my point as well. If its by design that's fair enough, but i would still be curious to why its that way. I also agree that even if it is by design it should shown an error/info message.

@rowanmiller
Copy link
Contributor

We know we need to improve this and that work is tracked by #3879. For the moment, did you specify --targetProject EmptyDB.Data to the update command too?

@rowanmiller
Copy link
Contributor

Also opened #4008 as a helpful enhancement that came up while we were discussing this.

@lasrol
Copy link
Author

lasrol commented Dec 9, 2015

Yes tested with dnx ef database update --targetProject EmptyDB.Data that also created an empty db.

@rowanmiller
Copy link
Contributor

Thanks for confirming.

Chaining a call to .MigrationsAssembly("EmptyDB.Data") after the call to UseSqlServer in Startup.cs should make things work.

@lasrol
Copy link
Author

lasrol commented Dec 10, 2015

In my repo i have the migration files in EmptyDB.Migrations, so i ùsed .MigrationsAssembly("EmptyDB.Migrations") this is also where i have a extra startup.cs but that did indeed work when correcting to the migrations project.

@rowanmiller
Copy link
Contributor

@lasrol thanks for confirming.

@bricelam is there anything here that you want to track in addition to #3879, or can I close this one out?

@bricelam
Copy link
Contributor

No, I think everything is tracked by other issues.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants