Debugging foreign key issue

Debugging foreign key issue

  
Hello,

I have been following the tutorials, and I must have made an error along the way, now getting an error on INSERT with foreign key issue.
I thought this was a good opportunity to learn how the debugger works, so have set up some break points and trying to step through the problem.
My trouble is, it seems that there is a discrepancy in the filter because the relationship has some error.
How can I see the actual INSERT statement that is being executed?  I only know there is an INSERT from the error message, but cannot figure out how to look at the actual SQL statement.
This is the error message coming up, in Save command.
The INSERT statement conflicted with the FOREIGN KEY constraint "OSFRK_OSUSR_L2M_ORDERITEM_OSUSR_L2M_ORDER_ORDERID". The conflict occurred in database "K1VTXU003", table "dbo.OSUSR_L2M_ORDER", column 'ID'.

Please advise.
Solution
Hi Yokho,

The only way to get to the actual INSERT statement is to use tooling of the database. However, you shouldn't need to do that in this case.

As you can see from the error message, there's a foreign key constraint conflict. This means that you try to INSERT a record (i.e. create a new one) that has an identifier of another table as one of its attributes, but that attribute is not filled correctly (i.e. either empty but it's mandatory, or filled with a value that does not exist in the referenced table).

Judging from the error message, you are trying to Create an OrderItem, but the mandatory OrderId is not filled correctly. You probably left it empty?
Solution
Yes, you were right, I needed another asign to fill the foreign key.  Thank you!

Hi, I'm having similar problem error while i give rating to the movie. My error is

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

i am assigning the three statements but the id attribute of "usermovierating" table is not assigning.

Can u tell me the solution i'm newbie in Outsytems

thankx

Hi Usama,

As you can see from the error message, the error is about the UserMovieRating Entity and the User Entity, and specifically about the "Id" Attribute ("column" in the message).Very likely, you have a UserId in the UserMovieRating Entity that's Mandatory, but you are creating or updating it without setting a proper UserId (one that is not NullIdentifier() and exists in the User Entity).

As i'm following the tutorials exercises so acc. to that i have assigned three conditions. that are:

"GetUserMovieRating.List.Current.UserMovieRating.UserId =GetUserId()

GetUserMovieRating.List.Current.UserMovieRating.MovieId =MovieId

GetUserMovieRating.List.Current.UserMovieRating.Rating =TextToInteger(NotifyGetMessage())"

i'm providing the userId of current logged in user but still it throws error. i'm newbie in outsystems so i couldn't configure whats wrong with the assign statements.

I'll be thankful to you..


Hi Usama,

GetUserId() can actually return NullIdentifier() if you're not logged in. Did you debug to see if it returns a valid value?

Kilian Hekhuis wrote:

Hi Usama,

GetUserId() can actually return NullIdentifier() if you're not logged in. Did you debug to see if it returns a valid value?


hi kilian,

my enviornment is down now..its not connecting to outsystems cloud..i'll check this when i'll contact to and will let you know

Hi Kilian,

Can you highlight why this movie id is not going with the rating notification other than first row record?

I am having this issue whenever i rate any movie.first i inserted if statement to check whether it is registered user or not, it was working fine for only first row record but when i select any other movie and rate it through this exception. 

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


Hi Usama,

Please debug the problem, by setting a breakpoint on the UpdateUserMovieRating statement, and checking which values you are trying to write to the database. UserId should be filled, and should have a valid value.