英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论