I'm trying to run my migrations but keep getting the following error.
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `votes` add constraint `votes_topic_id_foreign` foreign key (`topic_id`) references `voting_topic_results` (`division_id`))
I have tried both solutions in this post with no joy.
My two migration files are:
voting_topic_results
public function up()
{
Schema::create('voting_topic_results', function (Blueprint $table) {
$table->id();
$table->integer('division_id');
$table->dateTime('date');
$table->string('title');
$table->string('description')->nullable();
$table->integer('aye_count');
$table->integer('noe_count');
});
}
votes
public function up()
{
Schema::create('votes', function (Blueprint $table) {
$table->id();
$table->integer('topic_id');
$table->foreign('topic_id')->references('division_id')->on('voting_topic_results');
$table->integer('user_id');
$table->foreign('user_id')->references('id')->on('users');
$table->integer('user_aye_count')->nullable();
$table->integer('user_noe_count')->nullable();
$table->unique(['topic_id', 'user_id']);
});
}
EDIE***
I've updated my code to what the related question was referring to and I'm still getting the same error.