Laravels 移行を使用して、外部キーを持つ複数のテーブルを作成しようとしています。私はそのような移行テーブルに問題があります
Schema::create('problems', function($table)
{
$table->increments('id');
$table->integer('created_by')->unsigned();
$table->foreign('created_by')->references('id')->on('users');
$table->integer('category')->unsigned();
$table->foreign('category')->references('id')->on('categories');
$table->timestamps();
});
カテゴリの移行
Schema::create('categories', function($table)
{
$table->increments('id');
$table->string('category_name');
$table->timestamps();
});
ユーザーの移行への最初の外部キーは正常に機能しますが、カテゴリ ID の外部キーにヒットするとすぐに、
SQLSTATE HY000 General Error 1215 Impossible d'ajouter des contraintes d'index externe (SQL; alter table 'problems' add constraint problems_category_foreign 外部キー ('category') 参照 'categories' ('id'))
(私はフランス語を正しく読むことができず、なぜフランス語でエラーが発生するのかわかりません。私はフランス語ではないため、フランス語を変更する方法を見つけることができず、理解することもできません)
それらが本質的に同じものであるのに、なぜこれが一方では機能し、他方では機能しないのか理解できません。