5

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
1
  • Did you follow the link to learn about Code First Migrations? That's how to update your database without dropping it using EF. Commented Mar 4, 2013 at 16:31

1 Answer 1

4

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>());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.