Postgresql 无法使用实体框架核心3.1.3更新数据库
我正在为ASP.NETWebAPI应用程序使用EFCore,并尝试从我的模型创建PostgreSQL数据库(基本Microsoft文档示例) 我使用“添加迁移””创建迁移,但下一步,当我执行“更新数据库””时,出现以下错误:Postgresql 无法使用实体框架核心3.1.3更新数据库,postgresql,asp.net-core,entity-framework-core,ef-code-first,ef-core-3.1,Postgresql,Asp.net Core,Entity Framework Core,Ef Code First,Ef Core 3.1,我正在为ASP.NETWebAPI应用程序使用EFCore,并尝试从我的模型创建PostgreSQL数据库(基本Microsoft文档示例) 我使用“添加迁移””创建迁移,但下一步,当我执行“更新数据库””时,出现以下错误: > fail: Microsoft.EntityFrameworkCore.Database.Command[20102] > Failed executing DbCommand (15ms) [Parameters=[], CommandType='Te
> fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
> Failed executing DbCommand (15ms) [Parameters=[], CommandType='Text',
> CommandTimeout='30'] CREATE TABLE "Blogs" (
> "BlogId" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
> "Url" text NULL,
> CONSTRAINT "PK_Blogs" PRIMARY KEY ("BlogId") );
> Npgsql.PostgresException (0x80004005): 42601: erreur de syntaxe sur ou près de « GENERATED »
嗯。所以,问题是我想使用PostgreSQL 9.4,但EF Core 3仅支持PostgreSQL 10及以上版本 解决方案是说您正在使用9.4版,并在上下文中添加了一个选项 Startup.cs上的示例:
services.AddDbContext<MyContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"), o => o.SetPostgresVersion(9, 4)));
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"), o => o.SetPostgresVersion(9, 4)));
}