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

前端 未结 7 752
Happy的楠姐
Happy的楠姐 2021-01-31 04:02

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 r

7条回答
  •  走了就别回头了
    2021-01-31 04:28

    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

提交回复
热议问题