I have a migration like this:
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->bigIncrements('id');
$table->text('name');
$table->unsignedSmallInteger('category_id');
$table->unsignedInteger('section_d');
$table->unsignedBigInteger('order');
$table->timestamps();
$table->foreign('category_id')
->references('id')->on('categories')
->onDelete('restrict');
$table->foreign('section_id')
->references('id')->on('sections')
->onDelete('restrict');
});
}
There are other migrations that work fine, but everytime "php artisan migrate" is ran it shows this error regarding the specific migration above. Error:
Illuminate\Database\QueryException :
SQLSTATE[HY000]: General error: 1005
Can't create table `api`.`posts` (errno: 150
"Foreign key constraint is incorrectly formed")
(SQL: alter table `categories`
add constraint `categories_category_id_foreign`
foreign key (`category_id`)
references `categories` (`id`) on delete restrict)
Do you know why?