0%

Entity Framework Migration

tourial

安装dotnet ef cli

1
dotnet tool install --global dotnet-ef

创建‘迁移’

1
dotnet ef migrations add QQsInitialCreate

issue: No project was found. Change the current working directory or use the —project option.

项目入口(startup)的csproj与models目录分离,如

1
2
3
4
├───MyProduct.API
│ └───startup.cs
└───MyProduct.Models
└───migrations

定位startup project:
1
2
cd MyProduct.Models
dotnet ef migrations add QQsInitialCreate --startup-project "D:\QQsWorkspace\MyProduct.API"

更新数据库(—startup-project参数略):
1
dotnet ef database update

参考 Microsoft Docs:Entity Framework Core 工具