@PHPjedi

Что за ошибка при миграции?

Здравствуйте!

Столкнулся с табой ошибкой. Как ее решить ?

Ошибка:
Illuminate\Database\QueryException  : SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `properties` add constraint `properties_property_type_foreign` foreign key (`property
_type`) references `property_types` (`id`))


Таблица Properties:
Schema::create('properties', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title', 50);
            $table->string('description', 255);
            $table->string('address', 120);
            $table->unsignedInteger('property_type');
            $table->foreign('property_type')->references('id')->on('property_types');
            $table->unsignedInteger('declaration_type');
            $table->foreign('declaration_type')->references('id')->on('declaration_types');
            $table->unsignedInteger('city');
            $table->foreign('city_id')->references('id')->on('cities');
            $table->integer('price');
            $table->integer('floor');
            $table->integer('rooms');
            $table->string('area', 10);
            $table->unsignedInteger('uploaded_by');
            $table->foreign('uploaded_by')->references('id')->on('users');
            $table->timestamps();
        });


Property_types:
Schema::create('property_types', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title', 50);
            $table->string('slug', 50);
            $table->timestamps();
        });


Прошу вас помочь мне в решении этой ошибки...

Заранее большое спасибо!
  • Вопрос задан
  • 108 просмотров
Решения вопроса 1
@Novikofff
PHP Developer
Сначала выполняешь миграцию Property_types, потом Properties, и будет тебе счастье
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы