mysql - Yii2 - 使用 LONGBLOB 字段创建迁移

标签 mysql yii2

我想创建一个包含 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/

相关文章:

php - mysqli准备的问题变量数量不匹配

php - 如何使自定义设置数据在 Yii 2 中全局可用?

php - 保存到 MySQL 的速度慢(PHP - Yii2)

php - 一个数据库或单独数据库中的所有客户?

php - 如何获取 Yii2 中所有登录用户的列表?

php - SQL 将 "-large"附加到列名称为 "clean_name"的每隔一行

python - 操作错误(1054, "Unknown column ' 月'在 'field list' 中)

mysql - Yii2 - 两个查询的并集

mysql - SQL:寻求有关表结构等的建议

PHP 随机查询