it:ad:code_first:migrations:howto:strategies

IT:EF/CodeFirst/Migrations:HowTo:Strategies

  • Invoke Enable-Migrations with -AutoMigrations turned on, in order to start the migration with no InitialMigration in the Migrations Folder.
  • If:
    • you'll be applying migrations to a database structure that will be created by other means (ie by an imported initial script): invoke Add-Migration with -IgnoreChanges in order to create a blank InitialMigration.
      • If you don't, when running Migrations, the InitialMigration will try to create already existing tables, and cause an exception.
    • if your script will be creating the database, then just call Add-Migration to create an InitialChanges that creates the tables.
  • Once the InitialChanges migration is created, Disable Automatic Migrations so that you have to always create Coded Migrations.
  • Whether you were using a DbContext initialiser that was dropping/recreating the database or not, switch to a Migrations based initialiser.
    • If the db changes, it will ensure that a coded migration is created, then applied (no need to manually call Update-Database.
  • /home/skysigal/public_html/data/pages/it/ad/code_first/migrations/howto/strategies.txt
  • Last modified: 2023/11/04 02:19
  • by 127.0.0.1