我想创建一个包含 LONGBLOB 字段的表。
'image' => $this->binary(),
在表中生成BLOB字段。
除了对特定字段使用原始 SQL 语法之外,还有其他方法可以生成 LONGBLOB 字段吗?
下面是我创建表格的完整代码。
$this->createTable('edition_images', [
'image_id' => $this->bigPrimaryKey()->unsigned(),
'embed_url' => $this->string()->notNull(),
'image_type' => $this->string(),
'image_md5' => $this->string(),
//'image' => $this->binary(),
'`image` longblob NULL',
'title_en' => $this->string(),
'title_bg' => $this->string(),
'title_ro' => $this->string(),
'order' => $this->bigInteger(20)->unsigned()->null(),
'edition_id' => $this->bigInteger(20)->unsigned()->notNull(),
'created_by' => $this->bigInteger(20)->unsigned()->notNull(),
'created_at' => $this->timestamp()->notNull()->defaultExpression('CURRENT_TIMESTAMP'),
'updated_by' => $this->bigInteger(20)->unsigned()->null(),
'updated_at' => $this->timestamp()->null()->defaultValue(null)->append('ON UPDATE CURRENT_TIMESTAMP'),
'deleted_by' => $this->bigInteger(20)->unsigned()->null(),
'deleted_at' => $this->timestamp()->null(),
'deleted' => $this->integer(1),
]);
最佳答案
您可以将确切的列类型作为文本传递:
'image' => 'LONGBLOB'
您应该能够将长度指定为 binary
中的参数。方法。由于 longblob 为 4GB,因此您必须以字节为单位指定:
'image' => $this->binary(4294967295),
但是,$length
被忽略。代码
$this->db->createCommand()->createTable("test_blob", [
"id" => $this->integer(),
"datum" => $this->binary(429496729),
"txt" => $this->string()
])->getSql();
返回以下 SQL:
CREATE TABLE `test_blob` (
`id` int(11),
`datum` blob,
`txt` varchar(255)
);
我添加了 issue on Github
关于mysql - Yii2 - 使用 LONGBLOB 字段创建迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39721423/