Laravel 迁移主(或键)“标识符名称太长”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28626906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel migration primary (or key) "Identifier name is too long"
提问by Ifnot
I have simple Laravel migration file specifying a composite primary key :
我有一个简单的 Laravel 迁移文件,指定了一个复合主键:
// ...
public function up()
{
Schema::create('my_super_long_table_name', function($table)
{
$table->integer('column_1');
$table->integer('column_2');
$table->integer('column_3');
$table->primary(['column_1', 'column_2', 'column_3']);
});
}
// ...
And when running php artisan migrate
this error is thrown :
并在运行时php artisan migrate
抛出此错误:
SQLSTATE[42000]: Syntax error or access violation: 1059 Identifier name 'my_super_long_table_name_column_1_column_2_column_3' is too long
回答by Ifnot
Simply specify the key name when creating it (with the second argument for primary
).
只需在创建时指定键名(使用 的第二个参数primary
)。
$table->primary(['column_1', 'column_2', 'column_3'], 'my_long_table_primary');
Next,
下一个,
If you have error like You have an error in your SQL syntax ...
after this modification please make sure you are not using reserved word by your database engine for your key name.
如果You have an error in your SQL syntax ...
在此修改后出现类似错误,请确保您的数据库引擎没有使用保留字作为键名。
Eg for MySQL : http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html
例如 MySQL:http: //dev.mysql.com/doc/refman/5.6/en/reserved-words.html
Tip : primary
is reserved, so do not use it ;)
提示 :primary
是保留的,所以不要使用它;)