I'm new to EF code first. I have an existing database in production and I used EF 4.3.1 code first and everything worked. Now I just updated my database schema and got the exception
System.InvalidOperationException: The model backing the 'MyDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
I can't use
DropCreateDatabaseIfModelChanges since it is in production, what's the simplest way to take to cope with the schema change?
Since EF-CF migrations are a fairly new concept I would suggest taking an age-old proven process and modifying it to work with our new tools, like EF. Here's what we do:
DropCreateDatabaseIfModelChanges for local development. This will allow you to keep your local dev copy in sync with you Model (in code). Each time you build/run you get an updated local database. You can also use an Initializer to load test data, etc.
Use RedGate's SQLCompare tool to compare local dev to production and automatically generate a change script for deployment. (Note: you can also auto-deploy from the tool)
The key benefit is you don't have to change your local dev process AND you get a repeatable and versioned deployment via the generated script. You can also combine this with their SQL Source Control tool to keep all of your SQL objects and deployment scripts (even data) in source control.
NO, I DO NOT work for these guys I just love their tool and how it helped me with this very same problem.