Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How update database schema from EF5.0 model first changes?

I'm using VS2012 and EF 5.0 with a model first approach. I am wondering if there is any good way to generate incremental DDL to update model changes without dropping all the tables and losing the data I have in there already.

like image 281
Dave Avatar asked Mar 05 '26 02:03

Dave


1 Answers

I like to use a SQL server data project within Visual Studio to keep my data in sync with the database - it's like a mini SQL server schema store.

Basically what we are doing here is updating the schema of the data project using the model's DDL script, then comparing and pushing those changes out to the database. Just be sure to generate your model's DDL script first.

  1. Create a new SQL Server Database project
  2. Right click data project and import your existing schema from the database server
  3. Right click data project and import your generated DDL script from model first project.
  4. Right click data project and do a schema compare of your project vs. your database server
  5. Update database based on this schema compare (click update)

Every time you want to update your database just generate and import your models' sql script, compare, and update. It takes a couple steps but works perfectly.

like image 154
nh43de Avatar answered Mar 07 '26 14:03

nh43de



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!