I'm trying to migrate my messages/conversations/conversation_participants on a recently installed laravel project. The code works fine in testing, but doesn't work when I run php aritsan migrate
Error
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table messages add constraint messages_conversation_id_foreign foreign key (conversation_id) references conversations (id))
2020_07_13_000145_create_messages_table
Schema::create('messages', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('sender_id');
$table->unsignedBigInteger('conversation_id');
$table->text('body');
$table->timestamps();
$table->foreign('sender_id')->references('id')->on('users');
$table->foreign('conversation_id')->references('id')->on('conversations');
});
2020_07_13_053229_create_conversations_table
Schema::create('conversations', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('hashed_id')->nullable();
$table->unsignedInteger('has_reply')->unsigned()->default(0);
$table->text('subject');
$table->timestamps();
});
2020_07_14_045926_create_conversation_participants_table
Schema::create('conversation_participants', function (Blueprint $table) {
$table->integer('user_id')->unsigned();
$table->unsignedBigInteger('conversation_id');
$table->tinyInteger('status')->default(0);
$table->tinyInteger('is_sender')->default(0);
$table->foreign('conversation_id')->references('id')->on('conversations')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});