question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

connection error: Duplicate entry, need help!

See original GitHub issue

Issue type:

[ ] question [ ] bug

Database system/driver:

[ ] mysql / mariadb

TypeORM version:

[ ] latest

Steps to reproduce or a small repository showing the problem:

before: I already have a table in MySQL, such as: ±-------------±--------------±-----±----±--------±------+ | Field | Type | Null | Key | Default | Extra | ±-------------±--------------±-----±----±--------±------+ | id | decimal(10,0) | NO | MUL | NULL | | | user_name | varchar(30) | YES | | NULL | | ±-------------±--------------±-----±----±--------±------+ tips: no primary key data: ±-------------±--------------+ | id | user_name | ±-------------±--------------+ | 0 | Owen | | 1 | Tom | ±-------------±--------------+

after: I create entry : import { Entity, PrimaryColumn, Column, Index } from “typeorm”;

@Entity() export class User { @PrimaryColumn(‘decimal’) id: number; @Column() user_name: string; }

next: connection error: TypeORM connection error: { Error: ER_DUP_ENTRY: Duplicate entry ‘0’ for key ‘PRIMARY’ at Query.Sequence._packetToError (E:\Projects\ts-server\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14) at Query.ErrorPacket (E:\Projects\ts-server\node_modules\mysql\lib\protocol\sequences\Query.js:77:18) at Protocol._parsePacket (E:\Projects\ts-server\node_modules\mysql\lib\protocol\Protocol.js:279:23) at Parser.write (E:\Projects\ts-server\node_modules\mysql\lib\protocol\Parser.js:76:12) at Protocol.write (E:\Projects\ts-server\node_modules\mysql\lib\protocol\Protocol.js:39:16) at Socket.<anonymous> (E:\Projects\ts-server\node_modules\mysql\lib\Connection.js:103:28) at emitOne (events.js:96:13) at Socket.emit (events.js:188:7) at readableAddChunk (_stream_readable.js:176:18) at Socket.Readable.push (_stream_readable.js:134:10) -------------------- at Protocol._enqueue (E:\Projects\ts-server\node_modules\mysql\lib\protocol\Protocol.js:145:48) at PoolConnection.query (E:\Projects\ts-server\node_modules\mysql\lib\Connection.js:208:25) at MysqlQueryRunner.<anonymous> (E:\Projects\ts-server\node_modules\typeorm\driver\mysql\MysqlQueryRunner.js:193:44) at step (E:\Projects\ts-server\node_modules\typeorm\driver\mysql\MysqlQueryRunner.js:42:23) at Object.next (E:\Projects\ts-server\node_modules\typeorm\driver\mysql\MysqlQueryRunner.js:23:53) at fulfilled (E:\Projects\ts-server\node_modules\typeorm\driver\mysql\MysqlQueryRunner.js:14:58) at process._tickCallback (internal/process/next_tick.js:109:7) message: ‘ER_DUP_ENTRY: Duplicate entry '0' for key 'PRIMARY'’, code: ‘ER_DUP_ENTRY’, errno: 1062, sqlMessage: ‘Duplicate entry '0' for key 'PRIMARY'’, sqlState: ‘23000’, index: 0, sql: ‘ALTER TABLE user ADD id decimal NOT NULL PRIMARY KEY’, name: ‘QueryFailedError’, query: ‘ALTER TABLE user ADD id decimal NOT NULL PRIMARY KEY’, parameters: [] }

How to resolve? Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

42reactions
pleerockcommented, Apr 25, 2018

Probably you need to ask yourself what does ER_DUP_ENTRY: Duplicate entry '0' for key 'PRIMARY' sql error mean. This place isn’t for such questions.

1reaction
lemadanecommented, Jan 19, 2019

experienced this in repo.create(<multiple instance>)

Read more comments on GitHub >

github_iconTop Results From Across the Web

MySQL duplicate entry error even though there is no duplicate ...
The solution is to change the collation of a table, e.g. I used utf8_bin which is case-sensitive (or utf8_general_cs should be appropriate one...
Read more >
mysql - 1062 Duplicate entry but there are no duplicates?
If you run into this error for no apparent reason, check your foreign keys. Try a regular INSERT query (instead of REPLACE INTO...
Read more >
Bridge Connection - Duplicate Entry Error, Duplicated Data ...
This error message means that while adding any data in Store Manager, item with exactly same ID was added in your remote database,...
Read more >
Troubleshooting a Duplicate entry '0' for key 'PRIMARY' Error
This error occurrs when the primary key and auto_increment attributes are absent from one or more tables in the WHMCS database.
Read more >
Why does replication fail with error Duplicate entry for key?
Replication is complaining about the index called app . Evidently, you have a UNIQUE index on that column. Also, note the query's ON...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found