Support the ongoing development of Laravel.io →
Input Database Forms
Last updated 2 years ago.
0

Is it possible that every laravel table has to have an id field that is autoincrement?

No, you are not required to have one.

Is it true that all primary key fields have to be of the data type integer? is a primary key of the type string allowed as well?

I do not think you have to use a integer. I think it should work as long as both keys are of the same type.

a) Table1->Field1 (int) ---- Table2 ->Field2(int) compared to b) Table1->Field1 (int) ---- Table2 ->Field2(string)

I do not think b will work, which is what you have in your table scheme's.

You could also separate the foreign key creates from the table. I'm not sure it makes a difference, but I've seen it done this way more often. It is what I do also.

Schema::create('bureaucracy', function(Blueprint $table) { 
	$table->integer('number_of_civilian')->unsigned(); 	
)};

Schema::table('bureaucracy', function(Blueprint $table) {
   $table->foreign('number_of_civilian')->references('social_assurance_number')->on('person');
});

Hope that helps.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.