FOREIGN KEY constraint

FOREIGN KEY constraint


The attached eSpace is being designed for my pre-school.

I have students (Ogrenci) and some detail entities about them.

Every Ogrenci has only one Pedagog record and evey Pedagog record belongs to only one Ogrenci, so I tried to design the foreign key constraint to be one to one relation by arranging PedagogId as Ogrenci Identifier.

There are some other similar detail entities like GenelDurum, AnneSagligi and all of them have the same problem that I am trying to explain now.

In the OgrenciShow webpage, I have a tabbed design for these details.

Every detail has links in If container at the top for adding a new record or editing the existing record.

Editing the existing records works very well.

But when I try to add a new detail record (for example "Pedagog Kaydi Ekle" Link), after clicking the "Kaydet" (i.e. Save) button, I receive an error as:

The INSERT statement conflicted with the FOREIGN KEY constraint "OSFRK_OSUSR_8js_Pedagog_OSUSR_8JS_OGRENCI6_ID". The conflict occurred in database "outsystems", table "dbo.OSUSR_8JS_OGRENCI6", column 'ID'. The statement has been terminated.

Any suggestions?

Thanks in advance.



EDIT: I have only corrected some small syntax errors in the message.

Hi Rifat,

Looking at the eSpace my suspicion is that the assignment just before the CreateOrUpdatePedagog node inside the Pedagog_PopupEditor>Save is wrong. I assume you probably want it to read

Variable 1: PedagogEdit.Record.Pedagog.Id
Value 1: PedagogId

As it is, I assume CreateOrUpdate is being called with Id=nullidentifier on a new record, which is hitting the constraint for Ogrenci.

Let me know if this helped,

Hi Miguel,

It really worked.

Thanks for your help, thanks for the explanation.

Kind Regards,

I also am getting the same error. I have been trying to figure out all day how to fix it, but nothing has worked yet.

This is the exact error:

The INSERT statement conflicted with the FOREIGN KEY constraint "OSFRK_OSUSR_mka_CUSTOMER_OSUSR_4CX_COUNTRYIMPORT1_COUNTRY". The conflict occurred in database "outsystems", table "dbo.OSUSR_4CX_COUNTRYIMPORT1", column 'ID'.
The statement has been terminated.

I've attached the eSpace. I apologize if it's confusing ... Before using the Agile Platform I was a web designer, not a developer, so I may not be using the best methods for some things. Plus I've been awake for about 36 hours now working on this so it's probably something obvious and I'm just too tired to notice. ;)

I really appreciate any help! I'm completely stuck and of course this is supposed to go live tomorrow.

EDIT: Of course, being tired, I forgot to say where it was happening .... In the Main Flow, on the EnterInfo screen, after submitting the form (the "Next" action) I get the error.
Hi Britni...

The reason it's happening only for citizens outside Canada :) And why? Because you're most probably not assigning a country value (which is mandatory) when creating a Customer.

CustomerEdit.Record must have the country filled.

Have a nice Live ;)

The country is already assigned in the preparation based on the country they select in the Home screen. If the country is changed, the country is reassigned.

They also can get there from clicking "Edit" on the review page, in which case the country is also already assigned.
Hi Britni,

I didn't look too deeply into your eSpace but the AssignCountry node in the preparation looks suspicious: you're assigning directly to the Edit Record widget's country but at the end of the Preparation, when the screen gets data-bound, your Edit Record will grab the GetCustomerById.List.Current again (as per the Source Record prop) and ovewrite this assign.

Please have a second look at what you really wanted to do here.


If it is a new record, then I assign a default country in AssignCountry. If they are editing a record, then the country in GetCustomerById.List.Current overrides the default country.

I haven't had an problems at all with it not saving/displaying correctly. Nothing strange is happening to the data. I just keep getting the error. If this were just for internal use at my company, I wouldn't worry about it because you can just ignore the error and keep going without any problems. But there are going to be hundreds of customers using this that will panic when they see that error.
Hi Britni,
On the Preparation for EnterInfo screen, on the “AssignCountry” you should assing the countryid to “GetCustomerById.List.Current.CUSTOMER.Country”

(Reason: The “GetCustomerById.List.Current.CUSTOMER.Country” is the entity that will be used on the Edit Record. If you set the countryid directly to the “CustomerEdit.Record.CUSTOMER.Country”, after preparation it is overwrited)

Let me know if this solves your problem.


Márcio Spínola
Hi Britini,

Notice that you are also using the variable CustomerEdit.Record.CUSTOMER.Country in the assign and the edit record is not filled yet... it will have values only in the end of the preparation...

Carlos Rocha
I tried everything everyone suggested and nothing was working, so this is what I did...

The EnterInfo screen is no longer used as both a CREATE and EDIT screen. It is for creating only. Now, if customers need to edit their information, it takes them to a completely different page (in a popup). So it doesn't really solve the original problem technically, but at least now I don't have to worry about the error.

Thanks for the suggestions though everyone!