0

Using Code First and Entity Framework, I have created my web application on my dev machine, used migrations and published to my beta application to my production server and database.

Then on my dev system I’ve done lots of changes created several migrations and applied them to my local dev database. When I use update-database this updates my local dev database, but how then do I apply the migrations to my production server database?

I've been using update-database -script to get the SQL to manually apply to my production server. Is there a better way?

Art Vdel
  • 87
  • 6

2 Answers2

1

Your in Web.config is what establishes which database the application is pointing to. When you point it to production and run the same EF commands (dotnet ef migrations add migrationName, and dotnet ef database update) it should update your production environment.

For my setup I just don't deploy my web.config so in production it always points to production database. When I run the EF update scripts in production it updates production and I'm good to go.

Jacob M.
  • 750
  • 1
  • 6
  • 21
1

You should ideally employ some kind of actual database deployment system like ReadyRoll. Short of that, you should generate SQL scripts that you can commit and deploy manually, preferably via a DBA role in your organization. Code-based migrations can do all sorts of potentially bad things to your database with no notice, but in a SQL script, you can easily see that a table is about to be dropped or a column with lots of irreplaceable data is about to be removed.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444