Answer the question
In order to leave comments, you need to log in
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`))
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();
});
Schema::create('property_types', function (Blueprint $table) {
$table->increments('id');
$table->string('title', 50);
$table->string('slug', 50);
$table->timestamps();
});
Answer the question
In order to leave comments, you need to log in
First you migrate Property_types, then Properties, and you will be happy
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question