11
Views
3
Comments
Upgrade error while doing Reactive Training

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!

2025-04-15 10-28-35
Dhanasingh Dennison

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.

2024-10-05 13-30-20
Huy Hoang The

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. 

UserImage.jpg
Jayaprakash Ramesh

hi @Muhammad Arif Farhan
the correct way to fix it is 

Fix orphan data

Step-by-step

  1. Open Service Center

  2. Go to Monitoring → Error Logs

  3. Open the Upgrade Error

  4. Identify:>Environment>Module>Entities involved (State, Country)

  5. In Service Studio:>Open Data → Entities>Temporarily remove the Foreign Key (delete the reference >publish (this will succeed)

  6. Now fix the data:

    • Either delete invalid State rows

    • Or insert matching Country records

  7. Re-add the FK:

    • State.CountryId → Country.Id

    • Publish again

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.