0
0

More than 1 year has passed since last update.

LaravelのMigrationで外部キーを使用したら、エラー発生

Last updated at Posted at 2022-06-21

Laravelのmigrationをしようとした際、
スクリーンショット 2022-06-21 12.16.02.png

SQLSTATE[42000]: Syntax error or access violation: 1702 Key column 'categoryId' doesn't exist in table

というエラーにハマってました。

解決方法

unsignedBigIntegerを外部キー参照している前の行に記入!

unsignedBigInteger.php
$table->unsignedBigInteger('categoryId'); //ここ
$table->foreign('categoryId')->references('categoryId')->on('category')->onUpdate('RESTRICT')->onDelete('RESTRICT');

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