SQLSTATE[HY000]: General error: 1005 Can’t create table madhhab.issues (errno: 150 “Foreign key constraint is incorrectly formed”) (Connection: mysql, SQL: alter table issues add constraint issues_subchapter_id_foreign foreign key (subchapter_id) references subchapters (id) on delete cascade)
i droped the table from database then run the commands php artisan migrate:rollback
php artisan migrate:fresh , php artisan migrate:refresh
enter code here
All these and i dont know how i can fix it
i tried some of the answers form stakoverflow but didnt work
im expecting just to migrate the tables and start the work im stuck in this error for hoursss
// Your code goes here
public function up() {
Schema::create('issues', function (Blueprint $table) {
$table->id();
$table->text('title_ar');
$table->text('title_sq');
$table->timestamps();
});
}
public function up(): void
{
Schema::create('subchapters', function (Blueprint $table) {
$table->id();
$table->foreignId('chapter_id')->constrained('chapters')->onDelete('cascade');
$table->string('title_ar');
$table->string('title_sq');
$table->integer('display_order');
$table->timestamps();
});
}
Answer:
link