The INSERT statement conflicted with the FOREIGN KEY constraint

Hi Outsystem team, I have a problem this error The INSERT statement conflicted with the FOREIGN KEY constraint "OSFRK_OSUSR_TFX_PERSONMOVIEROLE_OSUSR_TFX_PERSON_PERSONID"  I am stack this error, I am beginner user of this platform. Please help me to resolve this issue. Thanks

This exercise from tutorial of web development I am currently on Data Queries and Widgets II Exercise

Hi John Mark  Panaguiton,

Make sure PERSONID your inserting is exists in persons table.


Sravan

Looks like you are trying to insert data in PersonMovieRole entity with invalid person ID. Just re-check if the person exists before inserting the related role. If this doesn't resolve the issue , more details around the entities would be required. 


Cheers,

TP

Solution

Hello John,

Let me give you some context so you can understand your problem.

This is a database exception. In more simple terms, it is saying that you are trying to insert a new record in entity PersonMovieRole, but the Person Identifier (FK In the PersonMovieRole entity referencing the Person entity) value you provided couldn't be found in the Entity Person. 

Being an FK (enforced by a constraint in database), if you provide a value different than NULL, the value MUST exist in the referenced entity.

So, what value you are passing? 

If you are not providing a value for an FK, OutSystems will check if the FK is mandatory or not. If it is mandatory, OutSystems will provide a default value: 0. Assuming the entity Person has an identifier Auto-number, their ids start at 1, hence the error from database.

You possibly forget to set the value for this FK, from the combo box, into the record you are using to save into db (like if the combobox is not bound to the Form). Or you are using a Form and the combo box is bound to its record but instead of passing the Form Record to the Create entity action, you are passing something else (like the Current of the Preparation Aggregate's list.

Hope this helps.

Cheers

Solution

Eduardo Jauch wrote:

Hello John,

Let me give you some context so you can understand your problem.

This is a database exception. In more simple terms, it is saying that you are trying to insert a new record in entity PersonMovieRole, but the Person Identifier (FK In the PersonMovieRole entity referencing the Person entity) value you provided couldn't be found in the Entity Person. 

Being an FK (enforced by a constraint in database), if you provide a value different than NULL, the value MUST exist in the referenced entity.

So, what value you are passing? 

If you are not providing a value for an FK, OutSystems will check if the FK is mandatory or not. If it is mandatory, OutSystems will provide a default value: 0. Assuming the entity Person has an identifier Auto-number, their ids start at 1, hence the error from database.

You possibly forget to set the value for this FK, from the combo box, into the record you are using to save into db (like if the combobox is not bound to the Form). Or you are using a Form and the combo box is bound to its record but instead of passing the Form Record to the Create entity action, you are passing something else (like the Current of the Preparation Aggregate's list.

Hope this helps.

Cheers

Thanks Eduardo!