我正在将我们的dotnet core项目更新为在后端使用PostgreSQL而不是Microsoft SQL Server,并遇到了两个表使用GUID作为数据类型的情况。
错误信息:
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Property CommentID on type is a database-generated uuid, which requires the PostgreSQL uuid-ossp extension. Add .HasPostgresExtension("uuid-ossp") to your context's OnModelCreating.
在稍微搜索了一下后,我意识到我需要启用 uuid 扩展(不确定是否可以自动化),然后在 pgAdmin 中成功生成了一个 uuid。
CREATE EXTENSION "uuid-ossp";
SELECT uuid_generate_v4();
很不幸,我的dotnet项目仍然出现相同的错误。 我在错误信息中看到它说要在OnModelCreating中添加.HasPostgresExtension("uuid-ossp"),我已经尝试了几个位置,但似乎无法确定应该在哪里添加。