迁移”是一组有序的步骤,描述如何升级(和降级)数据库架构。数据库
一、“工具”->“NuGet包管理器”->“程序包管理器控制台”
在程序包管理器控制台中运行 Enable-Migrations 命令架构
PM> Enable-Migrations Checking if the context targets an existing database... PM>
生成一个 Migrations 文件夹,它包含1个文件:Configuration.cs app
二、在程序包管理器控制台中运行 Add-Migration XX 命令。工具
XX 是名称,例如ddthis
PM> Add-Migration dd Scaffolding migration 'dd'. The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration dd' again. PM>
在文件夹 Migrations 中生成 文件:202108071428537_dd.cs ,前面是时间spa
三、在程序包管理器控制台中运行 Update-Database 命令。此命令将全部挂起的迁移应用于数据库。blog
PM> Update-Database Specify the '-Verbose' flag to view the SQL statements being applied to the target database. Applying explicit migrations: [202108071428537_dd]. Applying explicit migration: 202108071428537_dd. Running Seed method. PM>
一、定义UserAA模型类;ci
二、在DbContext 上下文中定义 public DbSet<UserAA> UserAA { get; set; }get
三、按照上面的步骤迁移it
一、删除UserAA模型类;
二、在DbContext 上下文中删除 public DbSet<UserAA> UserAA { get; set; }
三、按照上面的步骤迁移