Question

Violation of PRIMARY KEY constraint

according to my need I have created a new custom detail by following these steps:-

1) I've created a new object for my detail.

2) Next, using detail wizard I have created a new detail using the created object and then I have added few fields and that detail  I have added to my account section.

everything is working fine, but when I have tried to fill the fields  and save first under same account it was saved, but using the same account I tried to another one by filling the fields then I got this error how can I get out of this

 

Violation of PRIMARY KEY constraint 'PKKOuATTzB7cDsHskkp5OVQlx5Jog'. Cannot insert duplicate key in object 'dbo.guptaCompanyFleet'. The duplicate key value is (cad50d15-f28d-49fc-aa79-21615ac35b86). The statement has been terminated.

 

Like 0

Like

6 comments

Hi,

Check on what foreign key it is triggered and investigare connection in DB.

You may use this script: 

Select C.*, (Select definition From sys.default_constraints Where object_id = C.object_id) As dk_definition,

(Select definition From sys.check_constraints Where object_id = C.object_id) As ck_definition,

(Select name From sys.objects Where object_id = D.referenced_object_id) As fk_table,

(Select name From sys.columns Where column_id = D.parent_column_id And object_id = D.parent_object_id) As fk_col

From sys.objects As C

Left Join (Select * From sys.foreign_key_columns) As D On D.constraint_object_id = C.object_id

Where C.parent_object_id = (Select object_id From sys.objects Where type = 'U'

And name = '%Table name%') and type_desc = 'FOREIGN_KEY_CONSTRAINT' -- and C.name = 'PKKOuATTzB7cDsHskkp5OVQlx5Jog' 

Best regards,

Angela

Hi Gupta,

Please check the below following points.

1. Check whether correct lookup is mapped to the field in the detail. For example - Consider you are placing the Company fleet detail in Account's section, Company fleet detail should have a lookup mapped to Account.

2. Check whether the detail is properly mapped with correct field to the section in the section's edit page. For example - detail column should be the lookup which is pointing to 'Account' and the object column should be 'Id' of the account section.

3. If the error still persists, check for any key constraints as suggested by Angela using the above script in sql console.

Thanks,

Mohamed.

Hi Angela thank you for your reply, but how to connect to database or how to find the sql database.

 

Gupta,

If it is installed on premise you can connect to it via SQL manager, otherwise you can use SQL executor application

Angela

Yeah OKay thank you for your reply

 

Hello Chiadika,

 

Such error can have a few possible root causes, due to which the record/page is being saved twice. 



This way 2 requests InsertQuery are being sent to DB while saving the record, one of them is being processed correctly and creates a new record, the other one tries to create a record with already existing Id, which is impossible, so the system doesn't let to save the changes. 

It's possible to check the duplicate request in the Network console while recreating the case. I would advise to check it if the issue occurs again and as of now to double-check the mentioned in the notification objects (settings, etc) in your database to prevent similar situations in the future. 

 

Best regards,

Roman

Show all comments