现象:
在CodeFirst时,先写字段与表,创建数据库后,再添加内容
但字段与表会变更,比如改名·删除·增加等
需求:
当表字段变更时,同时变更数据库,执行数据库迁移
核心命令
Add-Migration firstMigration
update-database
步骤
打开程序包管理窗口
工具=>NuGet包管理器=>程序包管理控制台
Add-Migration代表迁移命令:后边参数为名称
输入命令:
Add-Migration firstMigration
但是可能会报错,提示EntityFramework的程序包未安装
Your target project 'ShangShangQian' doesn't reference EntityFramework. This package is required for the Entity Framework Core Tools to work. Ensure your target project is correct, install the package, and try again.
NuGet安装下