Create a migration : Add-Migration InitialCreate
Update the database : Update-Database
中间修改 migration 文件
migrationBuilder.AddColumn<string>(
name: "Name",
table: "Customer",
nullable: true);
migrationBuilder.Sql(
@"
UPDATE Customer
SET Name = FirstName + ' ' + LastName;
");
migrationBuilder.DropColumn(
name: "FirstName",
table: "Customer");
migrationBuilder.DropColumn(
name: "LastName",
table: "Customer");
删除最近的一次迁移文件 : Remove a migration
如果迁移文件已经 应用到数据库中 想回滚到某个 之前的迁移文件
Update-Database LastGoodMigration(你想回滚到的迁移文件)
Generate SQL scripts :Script-Migration
With From : Script-Migration 20190725054716_Add_new_tables
With From and To : Script-Migration 20190725054716_Add_new_tables 20190829031257_Add_audit_table