0

I'm currently developing an ASP.Net MVC 5. The problem is, I have always coded the websites and handed them over to other people who managed the deployment and maintenance. I have never been on the other side of the production and now I have to be. I have read some articles for ASP.Net MVC 3 but since I am creating this project with MVC 5, I was wondering what I should do in situations where the models need some changes. For instance:

  • I rename field or column
  • Add another field to the model with acceptable default values (maybe even null)
  • Remove a field
  • ...
Alireza Noori
  • 14,961
  • 30
  • 95
  • 179

1 Answers1

1

You should be able to generate the script needed to update your database. See this post for more information. Basically it says:

Run the Update-Database command but this time specify the –Script flag so that changes are written to a script rather than applied.

Open your package manager console (Tools > Library Package Manager > Package Manager Console), target your migrations project, and run "Update-Database -Script".

Then take the script and run it against your production / staging / testing / whatever environment.

Jack
  • 9,156
  • 4
  • 50
  • 75
  • Awesome. Just one question. Currently, I'm using the `Database.SetInitializer(new Ghazanet.Infrastructure.CustomInitializer());` to re-initialize the DB whenever I change the models. When should enable and build theinitial migration? – Alireza Noori Nov 15 '13 at 04:09
  • 1
    See http://stackoverflow.com/questions/10848746/using-entity-framework-code-first-migrations-in-production and the related links in that post for more information – Jack Nov 15 '13 at 04:58