I have some problems with migrating table on my laravel app. It always says
PDOException::("SQLSTATE[HY000]: General error: 1005 Can't create table
gamehosting.replies(errno: 150 "Foreign key constraint is incorrectly formed")")
But I don't see a problem with foreign key, here is the migration
public function up()
{
Schema::create('replies', function (Blueprint $table) {
$table->increments('id');
$table->text('body');
$table->integer('question_id')->unsigned();
$table->integer('user_id');
$table->foreign('question_id')->references('id')->on('questions')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('replies');
}
Btw, it's first adding this table and after that should add questions table, but error stops the migration. I set it to be first to migrate, but still same problem.