ASP.NET MVC 4, Migrations - How to run 'update-database' on a production server

niico picture niico · Jun 10, 2013 · Viewed 27.5k times · Source

I can use package manager to run 'update-database -verbose' locally.

Probably a stupid question but I can't find it online - once my website is deployed - how can I run this manually on the server?

Secondarily - what other strategies would you recommend for deploying database migrations to production - and how would they be preferable?

Thanks

Answer

amhed picture amhed · Jun 10, 2013

You have a couple of options:

  • You could use update-database -script to generate the SQL commands to update the database on the server
  • You could use the migrate.exe executable file that resides in the package folder on /packages/EntityFramework5.0.0/tools/migrate.exe. I've used it successfully in the past with Jet Brains' Team City Build Server to setup the migrations with my deploy scripts.
  • If you're using IIS Web Deploy you can tell the server to perform the migrations after publish (see pic below)
  • You could setup automatic migrations, but I prefer to be in control of when things happen :)

Update: Also, check out Sayed Ibrahim's blog, he works on the MsBuild Team at Microsoft and has some great insights on deployments

enter image description here