MediumBlob in Laravel database schema

為{幸葍}努か 提交于 2019-12-17 16:35:40

问题


How can I create a Mediumblob within the Laravel schema builder ?

In the docs it says :

$table->binary('data'); // BLOB equivalent to the table

But I need a MediumBlob otherwise the images get truncated at 64K; we are running MySQL.

I know that Laravel's schema builder is DB agnostic, but is there a way to avoid the "native way" and if not how can i create a Mediumblob column ?


回答1:


You can't.

This issue suggests using raw queries to create such columns, so you should do something like this in your migration file :

Schema::create("<table name>", function($table) {
    // here you do all columns supported by the schema builder
});

// once the table is created use a raw query to ALTER it and add the MEDIUMBLOB
DB::statement("ALTER TABLE <table name> ADD <column name> MEDIUMBLOB");



回答2:


The field is created but the file can not be inserted. And the following error is caused:

#1118 - Row size too large (> 8126)

Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help. In current row format BLOB prefix of 768 bytes is stored inline.



来源:https://stackoverflow.com/questions/20089652/mediumblob-in-laravel-database-schema

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!