Reputation: 46750
I am using Entity Framework Code First Migrations to make changes to my local database when someone makes a change to the data model. I run "update database"
when I want to incorporate database changes checked in from another developer and the model changes are made and the Seed method is called populating the database with the latest data.
I have just set up a CI environment with TeamCity to push code changes to the Latest build environment, the IAT environment and the UAT environment.
The problem is when I run the site an empty database is created but the Seed method is not run. How can I make the Seed method run as well as make it make any new database changes when I deploy?
Upvotes: 1
Views: 137
Reputation: 2881
The seed method should have run every time a developer runs Update-Database on their own DB. For a shared server, you can run migrate.exe on the command line against each server environment.
This executable is available in the Tools subfolder when you download EF via NuGet. If you want, you can automate its run by deploying it along with your application. Then, set up a command step in your CI configuration to call migrate.exe with the appropriate flags.
You can find more information on migrate.exe on MSDN:
http://msdn.microsoft.com/en-us/data/jj618307.aspx
e.g.
Migrate to the latest migration
Migrate.exe MyMvcApplication.dll /startupConfigurationFile="..\web.config"When running migrate.exe the only mandatory parameter is the assembly, which is the assembly that contains the migrations that you are trying to run, but it will use all convention based settings if you do not specify the configuration file.
Best of luck!
Upvotes: 1