J
J
Jedi2018-06-09 16:38:29
Laravel
Jedi, 2018-06-09 16:38:29

What's wrong with migration?

Hello!
Ran into your error. How to solve it?
Mistake:

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 table:
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();
        });

I ask you to help me in solving this error...
Many thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Novikov, 2018-06-09
@PHPjedi

First you migrate Property_types, then Properties, and you will be happy

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question