Article

How to fix the foreign key constraint errors

Hello!

This article helps you to figure out the constraint error upon saving a record in the system: "insert or update on the table 'Object_1' violates foreign key constraint 'FKxxxxxxx.'"

 

Foreign key constraint errors can pose challenges, but understanding their origins and solutions is crucial for maintaining database integrity.

Let's begin by noting that this error occurs at the database level because the data configured in the application does not align with the database integrity conditions (constraints).

Here's the analysis process:

1.Start by analyzing the error. Identify the constraint causing the issue and what it references (in this case, it's an Object_1 object). 
It appears that changes were made to the Object_1 object or related objects (such as adding new columns, removing columns/objects, editing column names, etc.).

Therefore, try opening the object in the configurations (the highest-level object is important) and reviewing all lookup fields, particularly the constant record parameter. 
Data integrity errors arise when values associated with the Object_1 object are deleted but the references are not updated.

2. If numerous lookup fields exist, simplifying the search by querying the database can be helpful. For instance, you can use a script:

SELECT * FROM information_schema.constraint_column_usage WHERE constraint_name = 'FKxxxxxxx';

This query will provide the field code, allowing you to review the field's parameters.

3. Another workaround without directly accessing the database is to examine the Insert or Update query structure through network tabs in the browser:

Try creating or modifying a record with the browser console open -> inspect the record, especially the lookup columns (the columnValues parameter on the payload tab) -> verify if the IDs used in the insert still exist in the associated tables. Alternatively, review these fields in the system configuration based on point #1.

 

These steps should help you diagnose and address the foreign key constraint error effectively.

Like 4

Like

Share

1 comments

Thank you ! These types of tutorial are missing in the academy and is welcome addition for anyone working in nocode mode

Show all comments