我正在使用Laravel作为我的网络应用程序。我正在使用php artisan migrate迁移一个表。
该表有316个列,其中有150个浮动列和150+字符串列。
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class Createtable_nameTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('table_name', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('column2');
$table->foreign('column2')->references('column1')->on('table1')->onDelete('cascade')->onUpdate('cascade');
$table->string('column3');
$table->string('column4');
$table->string('column5');
$table->string('column6');
$table->integer('column7')->unsigned();
$table->integer('column8')->unsigned();
$table->integer('column9')->unsigned();
$table->integer('column10')->unsigned();
$table->integer('column11')->unsigned();
$table->integer('column12')->unsigned();
$table->integer('column13')->unsigned();
$table->integer('column14')->unsigned();
$table->integer('column15')->unsigned();
$table->float('column16');
$table->float('column17');
.
.
.
.
$table->float('column166');
$table->string('column167');
.
.
.
$table->string('column316');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('table_name');
}
}我得到了以下错误:
SQLSTATE42000:语法错误或访问冲突: 1118行大小太大。-使用的表类型的最大行大小(不包括BLOB)为65535。这包括存储开销,检查manualSQLSTATE42000:语法错误或访问冲突: 1118行大小太大。使用的表类型的最大行大小(不包括BLOB)为65535。这包括存储开销,请检查手册。
发布于 2019-10-11 11:46:27
你问题的最后一行说你应该检查手册,阅读下面的表列计数和行大小的限制和行大小限制
MySQL的硬限制是每个表的列数为4096列,但对于给定的表,有效的最大值可能较小。准确的列限值取决于以下几个因素: 表的最大行大小限制列的数目(可能是大小),因为所有列的总长度不能超过此大小。请参阅行大小限制。 各个列的存储要求限制在给定的最大行大小内的列数。某些数据类型的存储需求取决于存储引擎、存储格式和字符集等因素。请参见数据类型存储要求。 存储引擎可能会施加其他限制,限制表列计数。例如,InnoDB的每个表的列限制为1017列。请参阅对InnoDB表的限制。有关其他存储引擎的信息,请参阅替代存储引擎。 每个表都有一个包含表定义的.frm文件。定义以可能影响表中允许的列数的方式影响此文件的内容。参见第12.6节,“.frm文件结构施加的限制”。
因此,基本上取决于存储引擎、存储格式和字符集。
发布于 2019-10-11 11:48:59
它是关于每行多少字节,而不是多少列。列的最大数量取决于列类型,因为每种类型占用特定的字节数。
我建议您更改数据库模型,并在外部表中将这些列作为行。您将有一个引用table_name和table_name_columns的table_name。
https://stackoverflow.com/questions/58340523
复制相似问题