Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF 5 - Model First, How to update DB Schema without dropping database

I am developing in MVC 4, EF 5.0

Model First development - how do I 'easily' get the DB schema to update, without having to drop the database / erase any data?

e.g. I have a Customer table. In this table, we capture name, surname, email address. I now want to collect the telephone number, so I change the model and get EF to update the database schema.

Visual studio 2012 referrs me to http://go.microsoft.com/fwlink/?LinkId=238269, however this looks like chinese to me.

They talk about running an NUGET package called code first migrations. Does this functionality not come packaged automatically with VS2012?

Thanks

like image 595
Gravy Avatar asked Oct 01 '12 18:10

Gravy


People also ask

How do I update the table schema in Entity Framework?

Drop and Recreate Your Database You can configure Entity Framework to delete (drop) and recreate your database every time there is a change to your schema. To do this, you need to create an initializer class in the same folder as your DbContext class. The class needs to inherit from DropCreateDatabaseIfModelChanges .


1 Answers

Database migrations is what you are looking for. Both automatic and specified in code - http://msdn.microsoft.com/pl-PL/data/jj591621

like image 171
Piotr Perak Avatar answered Nov 15 '22 10:11

Piotr Perak