jeudi 13 novembre 2014

EF Migrations both upgrade and initial create


Vote count:

0




I have recently been starting to use EF Migrations on a project. We have a test server where we want to clear the database at times and for that we have a db initializer program which drops the database and then recreates it and fill in some test data. We also have a production server which for obvious reasons never gets recreated only upgraded.


We have AutomaticMigrationsEnabled = false in the Configuration file.


The problem I have is that I can only have one of the servers to work at the same time. Our InitialCreate must have an empty Up() and Down() for the production server but must contain the full definition in Up() and Down() for the test server. If I run the code for the test server on the production server it says that the tables are already created. If I run the code for the production server on the test server it says that the table does not exists. So now when I want to create the database I have to fill in the Up(), create the database, drop the code inside Up() and then start the application. I have to do this as in my Application_Start() I have a call to the Migrations.Update().


So how do I solve this? I have tried to use:



  • Override AutomaticMigrationsEnabled = true on the test server and keep Up() and Down() Empty.

  • Tried to make an sql script that is run before Migrations.Update()

  • Tried to use context.Create()



asked 2 mins ago







EF Migrations both upgrade and initial create

Aucun commentaire:

Enregistrer un commentaire