Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot insert duplicate key row in object with unique index

I am trying to run the following query:

update OAR.oa_AcademicHead
set  personid=15857
where personid=1234

but I am getting the error:

Cannot insert duplicate key row in object 'OAR.oa_AcademicHead' with unique index 'IX_oa_AcademicHead_personid'.
The statement has been terminated.

What can be done to fix this??

like image 889
user3325454 Avatar asked Mar 05 '14 21:03

user3325454


1 Answers

A row where personid is 15857 already exists in the table. The unique index on that column is preventing you from committing another record with the same personid (an update is really a delete and insert).

You'll have to remove the existing person with that id first before running your query.*

* Disclaimer: make sure this is actually what you want to do; be aware of the issues it might cause.

like image 160
Cᴏʀʏ Avatar answered Oct 19 '22 23:10

Cᴏʀʏ