0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Identifier name '**65文字以上**' is too long エラーが出た時の対処法

Last updated at Posted at 2023-10-10

エラーメッセージ

 SQLSTATE[42000]: Syntax error or access violation: 1059 Identifier name '**65文字以上**' is too long (SQL: alter table `*` add constraint
   `**65文字以上**` foreign key (`*`) references `*` (`id`) on delete set null)

問題のコード

.php
//マイグレーションファイル内のコード
$table->foreign('*')->references('id')->on('*')->onDelete('set null');

原因

マイグレーションファイル内で65文字以上のnameを設定すると、長すぎる!と警告が出る。
特に外部キーだと長くなりがち。

対処法

外部キーの第二引数に個別のnameを付けることができるのでそれを利用する。

.php
$table->foreign('*', 'ここにnameを書く')->references('id')->on('*')->onDelete('set null');

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?