Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sevenTopo's avatar

Laravel and Foreign Keys

Hi every one .

i'm trying to create a database with some relationships bitwen 3 tables ,using the laravel docementation . my question is relate to sql :

Schema::enableForeignKeyConstraints();

Schema::disableForeignKeyConstraints();

what is the difference bitwen those 2 lines and what you guys recommanding ?

0 likes
2 replies
Snapey's avatar
Snapey
Best Answer
Level 122

You should enable them incase you want to use them.

FK Constraints enforce relationships. For instance, if you delete a user, then you could automatically have the database delete their associated posts and comments

This creates referential integrity

https://database.guide/what-is-referential-integrity/

sevenTopo's avatar

Thank you so much .now i can see the difference .

Please or to participate in this conversation.