Laravel迁移主要(或关键字)“标识符名称太长" [英] Laravel migration primary (or key) "Identifier name is too long"
问题描述
我有一个简单的Laravel迁移文件,它指定了一个复合主键:
I have simple Laravel migration file specifying a composite primary key :
// ...
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']);
});
}
// ...
运行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
推荐答案
在创建密钥名称时只需指定密钥名称(第二个参数为primary
).
Simply specify the key name when creating it (with the second argument for primary
).
$table->primary(['column_1', 'column_2', 'column_3'], 'my_long_table_primary');
下一步
Next,
如果在修改后出现类似You have an error in your SQL syntax ...
之类的错误,请确保您没有将数据库引擎的保留字用作键名.
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.
例如,对于MySQL: http://dev.mysql. com/doc/refman/5.6/en/reserved-words.html
Eg for MySQL : http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html
提示:primary
是保留的,所以不要使用它;)
Tip : primary
is reserved, so do not use it ;)
这篇关于Laravel迁移主要(或关键字)“标识符名称太长"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!