简体   繁体   English

Npgsql.PostgresException:类型“ltree”不存在

[英]Npgsql.PostgresException: type "ltree" does not exist

I'm developing a WebAPI with asp.net core .net5.0]我正在开发一个带有 asp.net 核心 .net5.0 的 WebAPI]

  • DataBase: PostgreSQL数据库:PostgreSQL
  • Provider: EF Core提供商:EF 核心
  • Approach: Code First方法:代码优先

In domain objects I've used Ltree for hierarchy.在域对象中,我将Ltree用于层次结构。 While adding and updating migration, getting followed error: Npgsql.PostgresException: type "ltree" does not exist .添加和更新迁移时,出现以下错误: Npgsql.PostgresException: type "ltree" does not exist

I did some research and found that, If I run "create extension Ltree" on PostgreSQL database, this will create extension for Ltree.我做了一些研究,发现如果我在 PostgreSQL 数据库上运行"create extension Ltree" ,这将为 Ltree 创建扩展。

In code first approach database will be created while adding and updating migrations, so I can not go to database and create an extension for that.在代码优先方法中,将在添加和更新迁移时创建数据库,因此我不能 go 到数据库并为其创建扩展。

My question is: is that possible creating an extension in migration?我的问题是:是否有可能在迁移中创建扩展?

public class Department
{
   public int Id { get; set; }
   
   [Column(TypeName = "Ltree")]
   public string Ltree { get; set; }
   
   public string Name { get; set; }
}

You can have EF Core create the extension for you by adding the following line in your model-building code (eg OnModelCreating):您可以通过在模型构建代码(例如 OnModelCreating)中添加以下行,让 EF Core 为您创建扩展:

modelBuilder.HasPostgresExtension("ltree");

Note that in version 7.0, the provider will automatically detect that an extension is needed (by going over your model properties), and will add the appropriate PostgreSQL extension without you having to do that explicitly (see https://github.com/npgsql/efcore.pg/issues/2137 ).请注意,在 7.0 版中,提供程序将自动检测是否需要扩展(通过检查您的 model 属性),并将添加适当的 PostgreSQL 扩展,而无需您明确地执行此操作(请参阅https://github.com/npgsql /efcore.pg/issues/2137 )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Npgsql.PostgresException 获取客户端可读消息 - Getting a client readable message from an Npgsql.PostgresException PostgresException:42883:尝试调用过程时,函数X(没有时区的时间戳)不存在 - PostgresException: 42883: function X(timestamp without time zone) does not exist when trying to call procedure 命名空间类型不存在 - Type of namespace does not exist Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal.NpgsqlOptionsExtension 类型中的方法“get_Info”没有实现 - Method 'get_Info' in type Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal.NpgsqlOptionsExtension does not have an implementation “JsonConvert”类型中不存在类型名称“serializeObject” - Type name 'serializeObject' does not exist in the type 'JsonConvert' npgsql CLR 枚举类型必须在使用前向 Npgsql 注册 - npgsql The CLR enum type must be registered with Npgsql before usage 错误:类型名称“X”不存在于类型“Y”中 - Error: The type name 'X' does not exist in the type 'Y' Npgsql:找不到CLR类型'NpgsqlDate'到关系类型的映射 - Npgsql: No mapping to a relational type can be found for the CLR type 'NpgsqlDate' 类型或名称空间名称“ SqlServer”在名称空间“ Microsoft.EntityFrameworkCore”中不存在 - The type or namespace name 'SqlServer' does not exist in the namespace 'Microsoft.EntityFrameworkCore' 命名空间“Microsoft”中不存在类型或命名空间名称“EntityFrameworkCore” - The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM