Mysql — php artisan перенести ошибку внешнего ключа

Мастер стол POll

 public function up()
{
Schema::create('poll', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->string('poll_question', 255);
$table->boolean('status',1)->default(0)->index();
$table->unsignedInteger('order');
});
}

Подробная таблица

  public function up()
{
Schema::create('poll_option', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('poll_id');
$table->string('poll_option', 255);
$table->unsignedInteger('vote_poll_option');
$table->unsignedInteger('order');
$table->boolean('status',1)->default(0)->index();

$table->foreign('poll_id')->references('id')->on('poll')->onUpdate('cascade')->onDelete('cascade');
});
}

Когда я запускаю php artisan с внешним ключом

SQLSTATE [HY000]: общая ошибка: 1005 Не удается создать таблицу mydb,#sql-6f4_433 (errno: 150 «Ограничение внешнего ключа сформировано неправильно»)

Примечание: я использую Ларавелла 5.2 а mysql типа уже Innodb какие основные причины неправильно сформированы

0

Решение

в таблице деталей

public function up()
{
Schema::create('poll_option', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('poll_id')->unsigned(); //Change Here
$table->string('poll_option', 255);
$table->unsignedInteger('vote_poll_option');
$table->unsignedInteger('order');
$table->boolean('status',1)->default(0)->index();

$table->foreign('poll_id')
->references('id')->on('poll')
->onDelete('CASCADE')
->onUpdate('CASCADE');
});
}

это будет работать для вас

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector