我遇到了一个奇怪的问题,找不到解决方法。
使用的技术栈是:NET Core 2、EF、PostgreSQL。
我使用 .NET Core Identity 并继承基本用户模型 User : IdentityUser
来添加额外的字段。
在我创建第一个迁移后,删除整个数据库并尝试 dotnet ef database update
时,总是会出现错误:42P07: relation "AspNetRoles" already exists
即使出现此错误,数据库和表也会被创建,但这使得迁移变得无用,因为它不保存已应用的迁移,所以我无法使用以下更改更新数据库...
fail: Microsoft.EntityFrameworkCore.Database.Command[200102] Failed executing DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] CREATE TABLE "AspNetRoles" ( "Id" text NOT NULL, "ConcurrencyStamp" text NULL, "Name" varchar(256) NULL, "NormalizedName" varchar(256) NULL, CONSTRAINT "PK_AspNetRoles" PRIMARY KEY ("Id") ); Npgsql.PostgresException (0x80004005): 42P07: relation "AspNetRoles" already exists at Npgsql.NpgsqlConnector.d__148.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() at System.Runtime.CompilerServices.ValueTaskAwaiter
1.GetResult()
at Npgsql.NpgsqlConnector.d__147.MoveNext()