Answer the question
In order to leave comments, you need to log in
Error creating migration?
Hello, I am creating a migration for posts
, here is the code
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->string('title');
$table->string('images')->nullable();
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->text('text');
$table->date('date')->nullable();
$table->boolean('view')->default(1);
$table->integer('category_id')->nullable();
$table->foreign('category_id')->references('id')->on('сategories');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('posts');
}
}
Answer the question
In order to leave comments, you need to log in
Or remove in this migration
$table->foreign('category_id')->references('id')->on('categories');
Or before this migration, make a migration that will create the categories table
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question