Error when editing entities.
See original GitHub issueDescribe the bug It’s a simple KOA server with TypeORM entities. When I edit any resource, an insert command instead of an update runs a give an error:
Installed libraries and their versions
“admin-bro”: “^3.3.1”, “@admin-bro/koa”: “^1.1.1”, “@admin-bro/typeorm”: “^1.4.0”,
To Reproduce Steps to reproduce the behavior:
- Go to any edit and change any data
- Click on save
- See error and on terminal de wrong SQL that has run.
Expected behavior Edit ends with success
Terminal
19:05:44 DEBUG koa Request POST /admin/api/resources/Organization/records/1/edit
query failed: INSERT INTO organization
(id
, version
, created_at
, created_by
, updated_by
, updated_at
, deleted_at
, deleted_by
, type
, name
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) – PARAMETERS: [“1”,1,“2020-12-15T22:04:05.617Z”,1,0,“2020-12-15T22:04:05.617Z”,null,0,“sponsor”,“Samsung1”]
error: Error: Duplicate entry ‘1’ for key ‘PRIMARY’
at Packet.asError (/Users/wagner-lagoasoft/dev/mmw/monorepo/node_modules/mysql2/lib/packets/packet.js:712:17)
at Query.execute (/Users/wagner-lagoasoft/dev/mmw/monorepo/node_modules/mysql2/lib/commands/command.js:28:26)
at PoolConnection.handlePacket (/Users/wagner-lagoasoft/dev/mmw/monorepo/node_modules/mysql2/lib/connection.js:425:32)
at PacketParser.onPacket (/Users/wagner-lagoasoft/dev/mmw/monorepo/node_modules/mysql2/lib/connection.js:75:12)
at PacketParser.executeStart (/Users/wagner-lagoasoft/dev/mmw/monorepo/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.<anonymous> (/Users/wagner-lagoasoft/dev/mmw/monorepo/node_modules/mysql2/lib/connection.js:82:25)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:295:12)
at readableAddChunk (_stream_readable.js:271:9)
at Socket.Readable.push (_stream_readable.js:212:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
code: ‘ER_DUP_ENTRY’,
errno: 1062,
sqlState: ‘23000’,
sqlMessage: “Duplicate entry ‘1’ for key ‘PRIMARY’”
}
AdminBroOptions with schema
branding: { companyName: ‘Company’, },
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
i have same issue… but i think that this is not admin-bro issue
If you are using the primary column as a bigint, you should apply the correct transformer.
https://github.com/typeorm/typeorm/issues/2400
This is still an issue today. Can’t save an edit for any entity with a bigint.
A sequelize column specified as this will produce a validation error on trying to save an edit: