> For the complete documentation index, see [llms.txt](https://docs.jgscripts.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.jgscripts.com/advanced-garages/troubleshooting/sql-error-foreign-key-constraint-fails.md).

# SQL error: foreign key constraint fails

"Cannot add or update a child row: a foreign key constraint fails...."

<figure><img src="/files/N4GduvrxAEMTAck41qlb" alt=""><figcaption><p>Example of the error</p></figcaption></figure>

This is a common issue with some QBCore installations. The way 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.

Fixing this issue is simple, just remove the constraint. Run the following SQL in your database:

```sql
ALTER TABLE player_vehicles DROP FOREIGN KEY FK_playervehicles_players
```

Some databases might use another name than the "FK\_playervehicles\_players" so make sure you change it to the one showing in your error

<figure><img src="/files/5461ouUHVgg6eB1yHacb" alt=""><figcaption><p>Example of another foreign key name</p></figcaption></figure>

In this example the foreign key name is `player_vehicles_ibfk_1` so the sql query will look like this:

```sql
ALTER TABLE player_vehicles DROP FOREIGN KEY player_vehicles_ibfk_1
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.jgscripts.com/advanced-garages/troubleshooting/sql-error-foreign-key-constraint-fails.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
