[Solved] SQLSTATE[HY000]: General error: 1824 Failed to open the referenced table (alter on Foreign key) Laravel

Mohamed Atef
Jun 13, 2021

--

I was facing this issue since 3 days and i’d like to share the solution,

the solution was by converting the type of sql engine in the table using the following code
<?php
$table->engine = 'InnoDB';
?>

so the Schema function of the table should be like this
<?php
public function up(){
Schema::create('posts', function (Blueprint $table) {
$table->engine = 'InnoDB'; //Add this line
$table->bigIncrements('id');
$table->string('title');
$table->string('post_url');
$table->string('img_path')->nullable();
$table->longtext('content');
$table->unsignedBigInteger('ownerID');
$table->foreign('ownerID')->references('id')->on('admins')->onDelete('cascade');
$table->timestamps();
});
}
?>

the reference https://web-brackets.com/discussion/4/-solved-sqlstate-hy000-general-error-1824-failed-to-open-the-referenced-table-alter-on-foreign-key-

--

--