dotnet ef migration add AddProduct
更新 database 前需添加类 TempDbContextFactory 如下:
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
namespace x01.SportWeb.Data
{
public class TempDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
{
public ApplicationDbContext CreateDbContext(string[] args)
{
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
builder.UseSqlite("Data Source=app.db");
return new ApplicationDbContext(builder.Options);
}
}
}
手工注释 Migrations/*_AddProduct.cs 中的 AddForeignKey 部分: