Я пытаюсь добавить новую таблицу в проект laravel 4x, в котором есть ссылка внешнего ключа на первичный ключ в существующей таблице, в которой уже есть данные.
Вот мой файл миграции для добавления новой таблицы
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCustomResponsesTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('custom_responses', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->integer('hotel_id')->unsigned();
$table->dateTime('created')->nullable();
$table->dateTime('last_changed')->nullable();
$table->string('response_type')->nullable();
$table->mediumText('custom_response')->nullable();
});
Schema::table('custom_responses', function($table) {
$table->foreign('hotel_id')->references('id')->on('properties');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('custom_responses');
}
}
Однако я также пробовал иметь такой файл миграции
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCustomResponsesTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('custom_responses', function (Blueprint $table) {
$table->increments('id');
$table->dateTime('created')->nullable();
$table->dateTime('last_changed')->nullable();
$table->string('response_type')->nullable();
$table->mediumText('custom_response')->nullable();
$table->integer('hotel_id')->unsigned();
$table->foreign('hotel_id')->references('id')->on('properties');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('custom_responses');
}
}
Когда я смотрю на существующую таблицу свойств, я вижу
Но когда я пытаюсь запустить миграцию, я получаю
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `custom_responses` add constraint custom_responses_hotel_id_foreign foreign key (`hotel_id`) references `properties` (`id`))
[PDOException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
При сканировании аналогичных вопросов по SO, а также поиске ошибки в Google типичными причинами являются несоответствие типов данных или новая таблица MyISAM, когда только InnoDB поддерживает внешние ключи. Из всего, что я могу видеть, создается новая таблица InnoDB и типы данных совпадают.
Может ли кто-нибудь указать, что мне не хватает?






propertiesиспользует двигательInnoDB?