Laravel Foreign key constraint incorrectly informed

0

I could not find the error in my migration, honestly.

Someone there can understand why I'm having the following error:

  

SQLSTATE [HY000]: General error: 1005 Can not create table    imobiliaria . #sql-2d3c_21 (errno: 150 "Foreign key constraint is   incorrectly formed ") (SQL: alter table imoveis add constraint    imoveis_capa _foreign foreign key ( capa ) references imagens   ( id ) on delete in action on update in action)

Migration:

   <?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateImoveisTable extends Migration
{
    /**
     * Schema table name to migrate
     * @var string
     */
    public $set_schema_table = 'imoveis';

    /**
     * Run the migrations.
     * @table Imoveis
     *
     * @return void
     */
    public function up()
    {
        Schema::dropIfExists('imoveis');
        Schema::create($this->set_schema_table, function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->integer('tipo_id')->unsigned();
            $table->string('nome');
            $table->float('valor');
            $table->integer('cidade_id')->unsigned();
            $table->integer('atributo_id')->unsigned();
            $table->text('descricao')->nullable();
            $table->integer('finalidade')->nullable();
            $table->float('area');
            $table->integer('quartos');
            $table->integer('banheiros');
            $table->integer('garagens');
            $table->integer('suites');
            $table->string('bairro')->nullable();
            $table->integer('capa')->unsigned()->nullable();

            $table->foreign('capa')->references('id')->on('imagens')
                ->onDelete('no action')
                ->onUpdate('no action');

            $table->foreign('tipo_id')
                ->references('id')->on('tipos')
                ->onDelete('no action')
                ->onUpdate('no action');

            $table->foreign('cidade_id')
                ->references('id')->on('cidades')
                ->onDelete('no action')
                ->onUpdate('no action');

            $table->foreign('atributo_id')
                ->references('id')->on('atributos')
                ->onDelete('no action')
                ->onUpdate('no action');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
     public function down()
     {
       Schema::dropIfExists($this->set_schema_table);
     }
}

Migration of images:

 <?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateImagensTable extends Migration
{
    /**
     * Schema table name to migrate
     * @var string
     */
    public $set_schema_table = 'imagens';

    /**
     * Run the migrations.
     * @table Imagens
     *
     * @return void
     */
    public function up()
    {
        Schema::create($this->set_schema_table, function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->string('urlImagem', 45)->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
     public function down()
     {
       Schema::dropIfExists($this->set_schema_table);
     }
}
    
asked by anonymous 21.12.2017 / 01:34

0 answers