我想创建一个包含LONGBLOB字段的表。
'image' => $this->binary(),
Run Code Online (Sandbox Code Playgroud)
在表中生成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),
]);
Run Code Online (Sandbox Code Playgroud)
您可以将确切的列类型作为文本传递:
'image' => 'LONGBLOB'
Run Code Online (Sandbox Code Playgroud)
您应该能够将长度指定为binary方法中的参数。由于 longblob 为 4GB,因此您必须以字节为单位指定:
'image' => $this->binary(4294967295),
Run Code Online (Sandbox Code Playgroud)
然而$length却被忽视了。代码
$this->db->createCommand()->createTable("test_blob", [
"id" => $this->integer(),
"datum" => $this->binary(429496729),
"txt" => $this->string()
])->getSql();
Run Code Online (Sandbox Code Playgroud)
返回以下 SQL:
CREATE TABLE `test_blob` (
`id` int(11),
`datum` blob,
`txt` varchar(255)
);
Run Code Online (Sandbox Code Playgroud)