Я пытаюсь запустить свои миграции, но продолжаю получать следующую ошибку.
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`))
Я пробовал оба решения в этом пост без радости.
Мои два файла миграции:
голосования_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');
});
}
голоса
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']);
});
}
ЭДИ***
Я обновил свой код до того, к чему относился соответствующий вопрос, и я все еще получаю ту же ошибку.
voting_topic_results
ваш столбецdivision_id
не имеет того же типа, что и ваше объявление вvotes
.$table->integer('division_id')->unique();
не равно$table->integer('topic_id')->unsigned();
поэтому возникает ошибка. После исправления убедитесь, что ваши схемыvoting_topic_results
переносятся доvotes
. - person Atchiiii   schedule 01.02.2021->unique()
и->unsigned()
, и все равно выдает ту же ошибку. - person CIB   schedule 01.02.2021voting_topic_results
доvotes
. - person Atchiiii   schedule 01.02.2021voting_topic_results
запускается первым - person CIB   schedule 01.02.2021