Когда вы создаете внешний ключ, categories.id
и posts.category_id
должны иметь одинаковый тип.
Поменяйте ->bigInteger()
на ->integer()
, чтобы решить вашу проблему:
Ваши категории миграции:
public function up(){
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
}
public function down(){
Schema::drop('categories');
}
В ваших публикациях миграция:
public function up(){
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->integer('category_id', false, true);
//Or $table->unsignedInteger('category_id');
$table->foreign('category_id')
->references('id')
->on('categories');
$table->timestamps();
});
}
public function down(){
Schema::drop('posts');
}
Надеюсь, это поможет.