Ifnot Ifnot - 1 year ago 184
MySQL Question

Laravel migration primary (or key) "Identifier name is too long"

I have simple Laravel migration file specifying a composite primary key :

// ...

public function up()
Schema::create('my_super_long_table_name', function($table)

$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

Answer Source

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');


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 ;)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download