Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identifier name 'long_table_names_blah_id' is too long #75

Open
jorenvanhee opened this issue Oct 13, 2015 · 1 comment
Open

Identifier name 'long_table_names_blah_id' is too long #75

jorenvanhee opened this issue Oct 13, 2015 · 1 comment

Comments

@jorenvanhee
Copy link

Getting this error:
[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1059 Identifier name 'snow_lesson_category_snow_mo nitor_snow_lesson_category_id_foreign' is too long

With this migration (or with any migration with long table names):
php artisan make:migration:pivot snow_monitors snow_lesson_categories

Can be solved by providing your own shorter key name.

$table->foreign('snow_lesson_category_id', 'snow_lesson_category_foreign')->references('id')->on('snow_lesson_categories')->onDelete('cascade');

This also happened with my primary key.

@pathros
Copy link

pathros commented Aug 13, 2024

In Laravel 11, I fixed it by adding the attribute indexName: in the ->constrained() method. On the other hand, the ->index() method is ignored. For example:

$table->foreignIdFor(\App\Models\User::class,'created_id')->nullable()->comment('user id who has created the record')
                ->constrained(\App\Models\User::make()->getTable(),indexName: 'custom_c_user_fk')->onUpdate('cascade')->onDelete('cascade');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants