Joseph Morgan
Published in : 2021-04-29
Hello everyone,
I am facing an issue with my table migration I am getting a weird error while running
php artisan migrate:fresh
The error is
SQLSTATE[HY000]: General error: 1824 Failed to open the referenced table 'blog' (SQL: alter table `blog_comments` add constraint `blog_comments_postid_foreign` foreign key (`postID`) references `blog` (`id`) on delete cascade) at C:\laravel\wp4world\vendor\laravel\framework\src\Illuminate\Database\Connection.php:671 667| // If an exception occurs when attempting to run a query, we'll format the error 668| // message to include the bindings with SQL, which will make this exception a 669| // lot more helpful to the developer instead of just the database's errors. 670| catch (Exception $e) { > 671| throw new QueryException( 672| $query, $this->prepareBindings($bindings), $e 673| ); 674| } 675|
Here is the migration file
<?phpuse Illuminate\Database\Migrations\Migration;use Illuminate\Database\Schema\Blueprint;use Illuminate\Support\Facades\Schema;class CreateBlogsTable extends Migration{ /** * Run the migrations. * * @return void */ public function up(){ Schema::create('blog', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('title'); $table->string('post_url'); $table->string('img_path')->nullable(); $table->longtext('content'); $table->string('tags'); $table->string('status')->default(0); $table->string('public_date', 30); $table->unsignedBigInteger('ownerID'); $table->foreign('ownerID')->references('id')->on('admins')->onDelete('cascade'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('blog'); }}
Does anyone know what is the issue about? I had checked everything and there is no error or any missing thing?
Thank you in advance
Join our community and get the chance to solve your code issues & share your opinion with us
Sign up Now
Jo Micheal Date : 2021-04-29
Best answers
6
Best answers
6
Hello Joseph,
As I see that your code is missing the InnoDB command to set the engine of the database to use ‘InnoDB’, please add this line in the up function
so it supposes to look like this
Good Luck :)
Joseph Morgan Date : 2021-04-29
Thank you Jo, this was a sally error, this is the first time to hear about the ‘InnoDB’