Recently I updated my software and I need to add a new table in my database. I am using
Update-Database -Force -Verbose
to update my database in my development PC. But when I install update version of my software in my client machine then it throw following exception.
The model backing the ‘MyContext’ context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269)
If I drop and recreate database then it`s work fine.
But it is quite impossible to drop existing database in my client machine. I have to add my new table without losing any data.
Please tell me how can i add a new table without out losing data in my existing Database.
I am using
Visual Studio 2012
Entity Framework 5.0
DotNet 4.0
MSSQL Server 2008 R2
You need to use Code First Migrations. When you set up your DbContext it will look something like this:
Database.SetInitializer<dbContext>(new MigrateDatabaseToLatestVersion<dbContext, Configuration>());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With