U moet de kolom met betrekking tot de externe sleutel maken:
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();
});
}
}
Soms (afhankelijk van uw databaseserver) moet u uw externe sleutels in twee stappen maken:
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');
});
}
}