Hello everyone!
I am quite new to outsystem. While I was going through with the training for Reactive (Reactive Programming Module > Fetching Data on Demand), I receive this error.
Upgrade Error: Could not create foreign key constraint. This may have happened because there are 'CountryId' values of entity 'State' with no corresponding value in entity 'Country', or attribute 'CountryId' of entity 'State' is creating a circular dependency between entities. Check the Error Log for more information.
I used to make clones before i start on new section that can be seen to be quite complex so just i can go back and practicing it again. Unfortunately, after I have created 3 new entities (state, country, city) and added some data into it, I realised that i was using a previous clone. So to not repeat the process again and make things easier (or so i thought), I decided to open the original module and just copy paste the new entities that I've created from this clone into my original module. Upon publishing, I received the error above.
Undo-ing this didn't help to get rid of this error.
I tried looking at this documentation, https://success.outsystems.com/documentation/11/reference/errors_and_warnings/errors/database_upgrade_error/, however there was no explanations on error like that.
Hope that you guys can help me out.
Thanks in advance!
Hi @Muhammad Arif Farhan ,
When you delete the attribute in OutSystems, the column is not deleted in the database. The column is disregarded from the data model, so from the point of Service Studio it doesn't exist, but it is still there. Because of that, when you try to have the new attribute with the same name, you get an error in the database server for trying to create another column with the name of an existing one. Try changing different name for the attribute that you have cloned.
Also, check this discussion below:
Upgrade error- Foreign key constraint-circular dependency between entities.
Thanks,
Dhanasingh Dennison T.
It's exactly.
And these conflicts often occur when you delete and clone content simultaneously in a single publish session. My advice is that you should divide it into several Publishs.
hi @Muhammad Arif Farhanthe correct way to fix it is
Fix orphan data
Step-by-step
Open Service Center
Go to Monitoring → Error Logs
Open the Upgrade Error
Identify:>Environment>Module>Entities involved (State, Country)
In Service Studio:>Open Data → Entities>Temporarily remove the Foreign Key (delete the reference >publish (this will succeed)
Now fix the data:
Either delete invalid State rows
Or insert matching Country records
Re-add the FK:
State.CountryId → Country.Id
Publish again