# Duplicate entry for PRIMARY key

**URL:** <https://community.open-emr.org/t/duplicate-entry-for-primary-key/9130>\
**Category:** Day-to-Day Users\
**Created:** [October 11, 2017, 6:10am UTC](https://community.open-emr.org/t/duplicate-entry-for-primary-key/9130 "2017-10-11T06:10:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![visolveemr](https://community.open-emr.org/user_avatar/community.open-emr.org/visolveemr/32/10974_2.png) [@visolveemr](https://community.open-emr.org/u/visolveemr)\
**Post date:** [October 11, 2017, 6:10am UTC](https://community.open-emr.org/t/duplicate-entry-for-primary-key/9130/1 "2017-10-11T06:10:16Z")

</div>

Calvince Ninga wrote on Wednesday Oct 11, 2017

Hello all,  
please anybody help me correct this error in my system, its a reccurent error in my system, the possible solution  
'Duplicate entry ‘64685’ for key ‘PRIMARY’.

---

<div class="post-metadata">

**Author:** ![visolveemr](https://community.open-emr.org/user_avatar/community.open-emr.org/visolveemr/32/10974_2.png) [@visolveemr](https://community.open-emr.org/u/visolveemr)\
**Post date:** [October 11, 2017, 6:12am UTC](https://community.open-emr.org/t/duplicate-entry-for-primary-key/9130/2 "2017-10-11T06:12:25Z")

</div>

@Calvince Ninga

The error has been generated is because there is already an existing value for the column ID in which you define it as PRIMARY KEY (values are unique) in the table you are inserting.  
Can you provide more information like screen or the operation that creates the error, we hope a screenshot will helps us better.

Thanks,  
[ViSolve](http://www.visolve.com/hc)

---

<div class="post-metadata">

**Author:** ![Jit\_Chawla](https://community.open-emr.org/user_avatar/community.open-emr.org/jit_chawla/32/14147_2.png) [@Jit\_Chawla](https://community.open-emr.org/u/Jit_Chawla)\
**Post date:** [August 16, 2023, 2:33pm UTC](https://community.open-emr.org/t/duplicate-entry-for-primary-key/9130/3 "2023-08-16T14:33:37Z")

</div>

Hello,  
I’m faced with the same issue. We couldn’t create a new encounter and then this issue popped up. It’s complaining of duplicate primary key for form\_encounter table and noticed the last entry is ID = 0. When we deleted that (as was for our test patient), it appears that did the same for the latest entry for that patient in forms table. When we deleted the patient tried to open new encounter on a real patient, same thing happened. On checking the table schema it seems that no issues easy identified and since working before with no table modifications not sure why that would be the etiology. Any advice would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![sjpadgett](https://community.open-emr.org/user_avatar/community.open-emr.org/sjpadgett/32/21623_2.png) [@sjpadgett](https://community.open-emr.org/u/sjpadgett)\
**Post date:** [August 17, 2023, 10:14pm UTC](https://community.open-emr.org/t/duplicate-entry-for-primary-key/9130/4 "2023-08-17T22:14:49Z")

</div>

Jit What is the highest id in form\_encounter?

---

<div class="post-metadata">

**Author:** ![Param\_CapMinds](https://community.open-emr.org/user_avatar/community.open-emr.org/param_capminds/32/17750_2.png) [@Param\_CapMinds](https://community.open-emr.org/u/Param_CapMinds)\
**Post date:** [August 22, 2023, 7:13am UTC](https://community.open-emr.org/t/duplicate-entry-for-primary-key/9130/5 "2023-08-22T07:13:17Z")

</div>

Hi [Jit Chawla](https://community.open-emr.org/u/Jit_Chawla),  
Make sure form\_encounter table column id primary key / autoincrement. I atteched here form\_encounter table for your reference  
[form\_encounter.sql](https://community.open-emr.org/uploads/short-url/quWlxgOmTAzgGsuMJ7k24GGfY45.sql) (3.3 KB)

Thanks ,  
Param,  
[help@capminds.com](mailto:help@capminds.com)

---

<div class="post-metadata">

**Author:** ![Jit\_Chawla](https://community.open-emr.org/user_avatar/community.open-emr.org/jit_chawla/32/14147_2.png) [@Jit\_Chawla](https://community.open-emr.org/u/Jit_Chawla)\
**Post date:** [September 2, 2023, 6:48pm UTC](https://community.open-emr.org/t/duplicate-entry-for-primary-key/9130/6 "2023-09-02T18:48:21Z")

</div>

Thanks guys! Working but the issue was that the doctor changed the data type of that column without telling anyone
