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

Migrations doesn't work with Beta 7 (Only Initial migration is found) #3160

Closed
timvanderweijde opened this Issue Sep 17, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@timvanderweijde
Copy link

timvanderweijde commented Sep 17, 2015

Hi,

I created a migration with
dnx ef migrations add Initial
dnx ef database update

After that I made some changes to the model and I added a new Migration Second
dnx ef migrations add Second.

Now when I try to update the database I get an error.
I tried:
dnx ef database update
dnx ef database update Second
dnx ef database update _Second

The error says the table is already created. This because the update tried to load the "Initial" migration again.

What can I do?

Cheers, Tim

@rowanmiller

This comment has been minimized.

Copy link
Member

rowanmiller commented Sep 18, 2015

@timvanderweijde can you provide some detailed steps for us to reproduce this? We are not able to get the same result. If you can provide initial code, the change you make, etc.

@timvanderweijde

This comment has been minimized.

Copy link

timvanderweijde commented Sep 19, 2015

Hi,

I started to create a demo project and I noticed a difference (and the reason why I got the error).

I also used another tutorial:
http://mvc.readthedocs.org/en/latest/tutorials/mvc-with-entity-framework.html

In there there a line:
if (context.Database.AsRelational().Exists())
{

But this line doesn't work with beta7 anymore. (the tutorial is behind)

I replaced this with this line:
context.Database.EnsureCreated();

So, before Migration I already created the database by running the application. And I quess if the database doesn;t have the table __MigrationHistory it will try to install the Initial migration script. This will always and up with an error related the table already exists. It would be nice to have a little bit more information of missing a MigrationTable e.g.

And how can I do "if (context.Database.AsRelational().Exists())" with beta 7?

Regards, Tim

@rowanmiller

This comment has been minimized.

Copy link
Member

rowanmiller commented Sep 30, 2015

Hey @timvanderweijde,

Ok that explains it, EnsureCreated totally bypasses migrations and just creates the schema for you, you can't mix this with migrations. EnsureCreated is designed for testing or rapid prototyping where you are ok with dropping and re-creating the database each time. If you are using migrations and want to have them automatically applied on app start, then you can use context.Database.Migrate() instead.

~Rowan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment