sql >> Base de Datos >  >> RDS >> Mysql

Laravel 4 Migraciones arrojando error 1072

Tienes que crear la columna relacionada con la clave foránea:

class CreateAreasTable extends Migration {

 /**
  * Run the migrations.
  *
  * @return void
  */
  public function up()
  {
    // Creates the cemeteries table
    Schema::create('areas', function($table)
    {
        $table->engine = 'InnoDB';
        $table->increments('id');

        $table->integer('region_id')->unsigned();
        $table->foreign('region_id')->references('id')->on('regions');

        $table->string('name', 160)->unique();
        $table->timestamps();

    });
  }
}

A veces (depende de su servidor de base de datos) tendrá que crear sus claves foráneas en dos pasos:

class CreateAreasTable extends Migration {

 /**
  * Run the migrations.
  *
  * @return void
  */
  public function up()
  {
    // Create the table and the foreign key column
    Schema::create('areas', function($table)
    {
        $table->engine = 'InnoDB';
        $table->increments('id');

        $table->integer('region_id')->unsigned();

        $table->string('name', 160)->unique();
        $table->timestamps();

    });

    // Create the relation
    Schema::tabe('areas', function($table)
    {
        $table->foreign('region_id')->references('id')->on('regions');
    });
  }
}