I have table category which have parent of type of itself.
Schema::create('categories', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->integer('parent_id')->unsigned()->nullable()->default(null);
$table->foreign('parent_id')->references('id')->on('categories');
$table->timestamps();
});
Throws:
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `categories` add constraint `categories_parent_id_foreign` foreign key (`parent_id`) references `categories` (`id`))
I've already tried making parent_id as foreign in seperate, Schema::table function yet with no success. Table is InnoDB type.