Reputation: 277
I need to update a test server database when deploying, and I do not find a way to do it. We are not using automatic migrations, so we do it manually.
Can I execute it on the test server directly? Maybe a console program?
I'm using the NuGet call for local development: Update-Database I know we can generate the script files, do I have to do it manually?
Upvotes: 1
Views: 1388
Reputation: 4986
You can use the MigrateDatabaseToLatestVersion database initializer to execute your migrations either through code or configuration. In code you'd do the following when the application starts:
Database.SetInitializer<MyContext>(
new MigrateDatabaseToLatestVersion<MyContext, MyMigrationConfig>()
);
Or in your app's .config file:
<entityFramework>
<contexts>
<context type="MyContext">
<databaseInitializer
type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[
[MyContext], [MyMigrationConfig]
], EntityFramework" />
</context>
</contexts>
</entityFramework>
Upvotes: 2
Reputation: 232
If your using Visual Studio, you can use the publish fonction to also execute a script. Look here for more détails:
http://learn.iis.net/page.aspx/1081/building-a-web-deploy-package-from-visual-studio-2010/
If your using team fondation server, you can even automate it:
Also to generate the script maybe you could use migrate.exe (it comes with ef 4.3 I think when getting the nuget package) and run it in a post build évent...
Upvotes: 0