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?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire