How to update entity framework 7 migrations and database - Code first

asp.net-core c# ef-code-first ef-migrations entity-framework-core

Question

In ef 7, i created an initial migration using command 'dnx ef migrations add Initial'. When i run the application database was created for me, all good.

Then i updated my entity objects (CSharp files). Now how can i do:

  1. Update the existing migrations ? (Or i have to add new one?)
  2. Update the already created database

I am getting error: An object already exists in database.

Also, any resources where i can find good practical examples for entity framework code first, as i am struggling to get to speed.

Thanks, Javed

1
3
3/5/2016 12:30:09 PM

Accepted Answer

Looks like i figure it out:

  1. Add initial migration (our your first one). Command 'dnx ef migrations add Initial'

  2. Run the application which will create the database for you.

  3. Update your entity models (csharp classes)
  4. Add a new migration again. DO NOT DELETE existing migration. Command: 'dnx ef migrations add Migration2'

  5. Update your database. Command 'dnx ef database update Migration2 -v'

Hope it helps anyone.

8
3/5/2016 12:29:25 PM

Popular Answer

Here's an in depth guide to using EF7 Migrations tools from Julie Lerman, a Microsoft MVP.

https://msdn.microsoft.com/en-us/magazine/mt614250.aspx



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