如何增加数组长度?值对于字符变量类型(255)太长。

huangapple go评论85阅读模式
英文:

How to increase array length? value too long for type character varying(255)

问题

It's possible to increase the length of an array. 我们可以增加数组的长度。

英文:

Is it possible to increase the length of an array?

I have tried adding length: 2048 and re-created the migrations (deleted migrations, dropped db, created db, and created new migration). It shows as missing_deposit_dates TEXT DEFAULT NULL

Running Symfony 6, PHP 8.2, PostgreSQL.

Column

#[ORM\Column(type: 'array', length: 2048, nullable: true)]
private ?array $missingDepositDates = [];

Exception

> An exception occurred while executing a query: SQLSTATE[22001]: String
> data, right truncated: 7 ERROR: value too long for type character
> varying(255)

答案1

得分: 2

It is setting your property as TEXT because the attribute length only applies to string columns.

There is no size limit on PostgreSQL arrays. This will make your make:migration command pass successfully:

#[ORM\Column(nullable: true)]
private ?array $missingDepositDates = [];

To limit the array length I would do it when I persist the changes of the entity in my PHP code. You could validate if the length of the current array is less than 2048 before persisting the changes.

英文:

It is setting your property as TEXT because the attribute length only applies to string columns. Doctrine property mapping

There is no size limit on PostgreSQL arrays. This will make your make:migration command pass successfully:

#[ORM\Column(nullable: true)]
private ?array $missingDepositDates = [];

To limit the array length I would do it when I persist the changes of the entity in my PHP code. You could validate if the length of the current array is less than 2048 before persisting the changes.

huangapple
  • 本文由 发表于 2023年3月20日 22:32:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75791596.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定