'Error with creating a laravel foreign key
I'm trying to create a relational database and this is the error i get
SQLSTATE[HY000]: General error: 1005 Can't create table
somedumbtable.meals(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter tablemealsadd constraintmeals_category_id_foreignforeign key (category_id) referencescategories(id))
Schema::create('meals', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('title_hr');
$table->string('title_en');
$table->string('description_hr');
$table->string('description_en');
$table->unsignedBigInteger('category_id');
$table->foreign('category_id')
->nullable()
->references('id')
->on('categories');
});
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('title_hr');
$table->string('title_en');
$table->string('slug')->unique();
});
Everything works fine if I remove the foreign key so the error is somewhere there and I do not seem to get it, any ideas?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
