EF data migration

 1. Tools -> Library Package Manager -> Package Manager Console

   2. Run the command Enable-Migrations,

      At this time, you will find that there is an extra folder called Migrations on the terminal, and there is a Configuration.cs file in it

   3. Run the command Add-Migration, this command will add a database migration file under the Migrations file, the content of the file is the code to create or modify the database table

   4. Run the command Update-Database or Update-Database -Force, execute the latest database migration file, and update the table information in the DB

        After the table is created, it is very simple to modify the table, directly modify the Model, and then execute Add-Migration, a database migration file will be automatically generated, and the table in the database will be updated when Update-Database is executed;

   There is another way to enable automatic migration, modify the Configuration under the Migrations folder, and change the value of AutomaticMigrationsEnabled to true, so that after modifying the Model, you can directly

  Then execute the Update-Database command to update the DB

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324983975&siteId=291194637