Advanced Garages
SQL error: foreign key constraint fails
"Cannot add or update a child row: a foreign key constraint fails...."

Example of the error
This is a common issue with some QBCore installations. When we set up job garages, we update the citizenid and set it to the name of the job. Some installations prevent this due to a database constraint.
To fix it, remove the constraint. Run the following SQL in your database:
ALTER TABLE player_vehicles DROP FOREIGN KEY FK_playervehicles_playersSome databases might use a different name from "FK_playervehicles_players", so make sure you change it to the one showing in your error.
![]()
Example of another foreign key name
In this example, the foreign key name is player_vehicles_ibfk_1, so the SQL query looks like this:
ALTER TABLE player_vehicles DROP FOREIGN KEY player_vehicles_ibfk_1