dimanche 1 mai 2016

Foreign key, or no foreign key? Defining Laravel relationships

What is the difference between defining a foreign key VS just creating an integer column named user_id?

$table->integer('user_id')->unsigned()->index();
// vs
$table->foreign('user_id')->references('id')->on('users');

Can they be used interchangeably? What purpose do each one serve? Which is considered a best practice, first or second definition?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1r82ZIk
via IFTTT

Aucun commentaire:

Enregistrer un commentaire