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']);
});
}
// ...
And when running php artisan migrate
this error is thrown :
SQLSTATE[42000]: Syntax error or access violation: 1059 Identifier name 'my_super_long_table_name_column_1_column_2_column_3' is too long
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,
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.
Eg for MySQL : http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html
Tip : primary
is reserved, so do not use it ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With