2

If I have an EF6 Code First environment in need of a schema change, is it possible to configure it in such a way that I can apply the migration (via Update-Database -Script) before the code gets deployed?

I just ran a simple test with a console app building a DB with migration "Initial", taking a copy of the application at this point. I then modified the schema by adding a new property to my entity and added a "V2" migration and ran Update-Database. When trying to run the "old" code against this migrated DB, I get an InvalidOperationException "The model backing the context has changed since the database was created."

Is the Continuous Delivery type operation where you might want one server running new application code with others running old versions possible with EF code first?

Darran
  • 593
  • 2
  • 13
  • can you modify old code ? if yes [disabling schema checking](http://stackoverflow.com/questions/10623260/how-can-i-disable-model-compatibility-checking-in-entity-framework-4-3) in old code is an option. Are you sure the added column is nullable or as a default value ? – tschmit007 Jul 21 '14 at 17:51
  • That looks ideal. This is for ongoing deployments so that we can run the scripted migration before we deploy the code so we can indeed disable the initializer. Many thanks. – Darran Jul 22 '14 at 08:22

1 Answers1

1

can you modify old code ?

if yes disabling schema checking in old code is an option.

btw: Are you sure the added column is nullable or as a default value ?

to avoid surprises, you can also use a connection string that has read only rights on the schema to avoid data corruption.

Community
  • 1
  • 1
tschmit007
  • 7,559
  • 2
  • 35
  • 43