如何在Laravel中最大化行大小mysql
我想最大化行描述的大小。我已经将大小设置为 10240 但它仍然显示错误。如何在此列中存储数据,因为我必须保存大量数据
public function up()
{
Schema::create('final_news', function (Blueprint $table) {
$table->id();
$table->integer('id_newspaper');
$table->string('heading');
$table->string('description', 10240);
$table->timestamps();
});
}
我得到的错误
SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'description' at row 1 (SQL: insert into `final_news` (`id_newspaper`, `heading`, `d
描述, updated_at , created_at`)
回答
如果字符串很长,您可以使用 longtext
$table->longText('description')
该longText方法创建一个LONGTEXT等效列:
参考:https : //laravel.com/docs/8.x/migrations#column-method-longText
- MySQL's `LONGTEXT` has a size limit of 4GB.