English 中文(简体)
Npgsql.PostgresException: 不能自动地将哥伦n按类别
原标题:Npgsql.PostgresException: Column cannot be cast automatically to type bytea

Using EF-Core for PostgresSQL, I have an entity with a field of type byte but decided to change it to type byte[]. But when I do migrations, on applying the migration file generated, it threw the following exception:

Npgsql.PostgresException (0x80004005): 42804: column "Logo" cannot be cast automatically to type bytea

我在互联网上寻找解决办法,但我看到,与其他数据类型,而不是星阵列存在类似问题。 请提供帮助。

最佳回答

误差完全说明发生的情况。 某些情况是,《员额编制法》允许对各组进行调整(例如,“条表”内“t” - ; 在这种具体的情况下,情况就发生,因为Npgskl把《公约》的外在地段作为《后天地法》的“日地”,因为《后天地法》缺乏1个具体数据领域。 因此,S postgreSkL不从(t)条code/条code到(t)条code/条条code到(t)条。

但是,你仍然可以通过撰写数据转换文件,从smallintbytea进行迁移。 为此,根据所形成的移徙,找到<代码>。 ALTER COLUMN ... AL TYPE statement and Add a USING/code> clauses. ,这允许你根据现有栏目(甚至其他栏目)提供该栏的新价值。 具体来说,为了将 in(或小int)改为 by,使用如下:

ALTER TABLE tab ALTER COLUMN col TYPE BYTEA USING set_bytea(E 0 , 0, col);

如果你现有的一栏含有不止一个星号(也许不是你的问题),那么就应当加以限制。 仔细测试从中得出的数据。

问题回答

Although the answer given by @Shay Rojansky is correct, I encountered some difficulties when trying to apply it as described above. I had to adjust it a bit to make it work for me:

请允许我说,我们有一个这样的实体:

public class Service
{
    public long Id { get; set; }

    public string? Name { get; set; }

    public string? Image { get; set; }
}

并且,你决定将“按年龄”的类型从“逐年”改为“逐年”,并在变动后产生你的移民。 PostgreSQL将提出一个例外,规定“不能自动转换成乙类”

正如“Shay Rojansky”已经指出的那样,你应该通过移民档案来找到如下内容:

migrationBuilder.AlterColumn<byte[]>(
    name: "Image",
    table: "Services",
    type: "bytea",
    nullable: true,
    oldClrType: typeof(string),
    oldType: "text");

如果你发现,你需要将其改为:

migrationBuilder.Sql(@"ALTER TABLE ""Services"" ALTER COLUMN ""Image"" TYPE BYTEA USING ""Image""::bytea");




相关问题
Entity Framework with MySQL connector in c#

I have been trying to get the Entity Framework to work in my web application using MySQL. It works fine on my local pc, but doesn t work when I put it on the server. Since the server is a shared ...

How Do I Create And Update A Many To Many Relationship With EF

I am using the Entity Framework with SQL Server. I have a many to many relationship between 2 tables. I have created a join table with just the primary key fields of the 2 tables. In the designer, the ...

Entity Framework with File-Based Database

I am in the process of developing a desktop application that needs a database. The application is currently targeted to SQL Express 2005 and works wonderfully. However, I m not crazy about having ...

Linq to enties, insert foreign keys

I am using the ADO entity framework for the first time and am not sure of the best way of inserting db recored that contain foreign keys. this is the code that i am using, I would appreciate any ...

Entity Framework - Many to many question

I have a table called ASB and a table called PeopleInvolved. There is a junction table called PeopleInvolved_ASB which simply contains an ASBID and a PeopleInvolvedID column. The columns act as a ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

ADO.NET Entity Data Model are not precise enough

I run this code: var cos = from k in _db.klienci_do_trasy where k.klient_id == 5 select k; but the query send to database is: SELECT * FROM `klienci_do_trasy` LIMIT 0, 30 why is it for, there ...