connection error: Duplicate entry, need help!
See original GitHub issueIssue 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:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
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.experienced this in repo.create(<multiple instance>)