[英]Getting a client readable message from an Npgsql.PostgresException
[英]Npgsql.PostgresException: type "ltree" does not exist
我正在開發一個帶有 asp.net 核心 .net5.0 的 WebAPI]
在域對象中,我將Ltree
用於層次結構。 添加和更新遷移時,出現以下錯誤: Npgsql.PostgresException: type "ltree" does not exist
。
我做了一些研究,發現如果我在 PostgreSQL 數據庫上運行"create extension Ltree"
,這將為 Ltree 創建擴展。
在代碼優先方法中,將在添加和更新遷移時創建數據庫,因此我不能 go 到數據庫並為其創建擴展。
我的問題是:是否有可能在遷移中創建擴展?
public class Department
{
public int Id { get; set; }
[Column(TypeName = "Ltree")]
public string Ltree { get; set; }
public string Name { get; set; }
}
您可以通過在模型構建代碼(例如 OnModelCreating)中添加以下行,讓 EF Core 為您創建擴展:
modelBuilder.HasPostgresExtension("ltree");
請注意,在 7.0 版中,提供程序將自動檢測是否需要擴展(通過檢查您的 model 屬性),並將添加適當的 PostgreSQL 擴展,而無需您明確地執行此操作(請參閱https://github.com/npgsql /efcore.pg/issues/2137 )。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.