Define longblob in migrate

Hi. I need store the large file into mysql db so the longblob is needed. However, I see yii2 only suppport blob

Below is my code in migrate script.




$this->createTable(

    '{{%media}}',

    [

        'id' => Schema::TYPE_PK,

        'mime_type' => Schema::TYPE_STRING . ' NOT NULL ',

        'size' => Schema::TYPE_STRING . '(32) NOT NULL',

        'file_name' => Schema::TYPE_STRING . '(256) NOT NULL',

        'data' => Schema::TYPE_BINARY . ' NOT NULL',

        'created_at' => Schema::TYPE_INTEGER . ' NOT NULL',

        'updated_at' => Schema::TYPE_INTEGER . ' NOT NULL',

        'user_id' => Schema::TYPE_INTEGER

    ],

    $tableOptions

);



I found only the Schema::TYPE_BINARY and you can see it’s assigned to data field which generate the shortblob.

so what’s the solution to generate field with longblob ?

The predefined Schema types are only strings so you don’t have to use them. If the type is supported by MySql then just use whatever type you want as a string:


'data' => 'LONGBLOB NOT NULL',

Bear in mind that MySql treats binary stuff as strings anyway so you might just get away with TEXT or VARCHAR(9999) or whatever. I have noticed that the blobs do store the length at the start of the field so that might be useful?

Yeah. I forgot about concat the string like this. it works well, thank.