I think increments makes the "id" to be primary. You can drop it with dropPrimary.
You cannot have two primary keys at the same time, you have to drop one and then create the other. Also, every constraint should be an index.
integer('city_id')->unsigned()->index();
Don't make composite primaries, because Eloquent doesn't support models with composite primary keys, use them only for pivot tables (Many-to-Many tables).
Don't create a composite primary key if you have an autoincrement column. That would be a violation against some of the normalization forms (NF2 or NF3, not sure).
Make the city_id a foreign key, and that's it.
Firtzberg said:
Also, every constraint should be an index.
integer('city_id')->unsigned()->index();
I don't believe you need the ->index() method because Laravel appears to automatically create an index for foreign keys.
For example, this code will generate a table with two indexes. A primary index with field "id" and another index with field "branch_id".
Schema::create('facility', function(Blueprint $table)
{
$table->increments('id');
$table->softDeletes();
$table->string('name', 45);
$table->integer('branch_id')->unsigned();
$table->foreign('branch_id')->references('id')->on('branch')->onUpdate('cascade')->onDelete('restrict');
});
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community