it:ad:code_first:migrations:howto:update-database

IT:AD:EF/CodeFirst/Migrations:HowTo:Update-Database

All you have to do is something like:


//Probably the most used scenario:
// Generate an Incremental Script from last Applied Migration in Db till Current Code Model

Update-Database -StartupProjectName:App.AppHost.Web -projectName:App.AppHost.Infrastructure -verbose

If you have Enabled Automatic Migrations this is almost the easiest Migrations command to use.

This is because it handles the creation of Automatic Migrations before applying them, in effect making your development story:

  • Make changes to an Entity Mapping
  • Try to run your application
  • Get the Exception that says the Model has changes:
  • Use the Update-Database IT:AD:Powershell command to:
    • automatically calculate and create Automated Migrations, and
      • push the changes to our model to the database.
    • Advantages:
      • Nice and easy to get into Migrations – but it really is too easy (see Disadvantages below)
    • Considerations:
    • Disadvantages:
      • Dangerous!:
        • Often generates Migrations that contain DropTable and DropColumn without making any effort to copy the data first.
          • Not the kind of stuff that you want to slip into your code to be released to Production.
  • /home/skysigal/public_html/data/pages/it/ad/code_first/migrations/howto/update-database.txt
  • Last modified: 2023/11/04 02:19
  • by 127.0.0.1