gpt4 book ai didi

yii2 - 如何在Yii2迁移中将数据类型设置为长文本

转载 作者:行者123 更新时间:2023-12-04 13:30:30 26 4
gpt4 key购买 nike

我使用以下代码来获取bodytext的attribute的期望值。数据类型应为longtext()varchar()。 DBMS是MySQL。

使用以下代码,bodytext将被创建为varchar(255)。为什么?

$this->createTable('mail_eingang', [
'id' => $this->primaryKey(),
'mail_adresse_absender' => $this->string(255)->notNull(),
'betreff' => $this->string(255),
'bodytext' => $this->string(), //this will actually set bodytext to varchar(255). It should be longtext() or varchar() !!
'gelesen' => $this->smallInteger(1)->notNull()->defaultValue(0),
'angelegt_am' => $this->datetime(),
'angelegt_von' => $this->integer(11),
'aktualisiert_am' => $this->datetime(),
'aktualisiert_von' => $this->integer(11),
'FOREIGN KEY ([[angelegt_von]]) REFERENCES person ([[id]]) ON DELETE SET NULL ON UPDATE RESTRICT',
'FOREIGN KEY ([[aktualisiert_von]]) REFERENCES person ([[id]]) ON DELETE SET NULL ON UPDATE RESTRICT',
], $tableOptions);

最佳答案

如果您足够使用64 KB,则可以使用 text() :

'bodytext' => $this->text()

如果您确实需要一个longtext列,则应使用类似以下内容的内容:
'bodytext' => $this->getDb()->getSchema()->createColumnSchemaBuilder('longtext');

或将类型指定为原始字符串:
'bodytext' => 'LONGTEXT',

关于yii2 - 如何在Yii2迁移中将数据类型设置为长文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50076195/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com