EF 7 Migration to Existing Database

asp.net5 ef-migrations entity-framework-core

Question

I am working on a web project using ASP.Net 5 and EF7.

I have imported all the tables from existing database onto my models in my project. However, I am having problems in regards with migrations.

I have created the initial migration, made some changes on particular entity, create another migration following the changes I have made and now want to apply the changes on the database.

After running this command below:

dnx ef database update [Migration]

the dnx is trying to apply the 'initial' migration with all the entities which are already in database and this causes an error as below:

{ There is already an object named ['EntityName'] in the database. }

Can you please advise on how to do the migration on the existing database?

Thanks Saeed

1
8
8/11/2017 12:32:50 PM

Popular Answer

In EF6 you would run a migration with the -IgnoreChanges flag and it would take a snapshot of the model without any Up() code. This is missing from EF 7(EF Core) as indicated here.

The workaround for now is delete or comment out the code for existing database objects from the Up() code of the migration and then update-database. Subsequent migrations will then include only the changes.

8
8/11/2017 12:33:10 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow