flexxnn / sequelize-auto-migrations

Migration generator && runner for sequelize
MIT License
259 stars 165 forks source link

runmigration fails with UNIQUE KEY `PRIMARY` index #85

Open axlwild opened 3 years ago

axlwild commented 3 years ago

If I add explicitly the primary index I get an error of wrong name.

Example: { fn: "addIndex", params: [ "admins", [{ "name": "id" }], { "indexName": "PRIMARY", "name": "PRIMARY", "indicesType": "UNIQUE", "type": "UNIQUE" } ] },

Error: Executing (default): ALTER TABLEadminsADD UNIQUE INDEXPRIMARY(id) DatabaseError [SequelizeDatabaseError]: Incorrect index name 'PRIMARY' at Query.formatError (/node_modules/sequelize/lib/dialects/mysql/query.js:239:16) at Query.run (/node_modules/sequelize/lib/dialects/mysql/query.js:54:18) at processTicksAndRejections (internal/process/task_queues.js:97:5) { parent: Error: Incorrect index name 'PRIMARY' at Packet.asError (/node_modules/mysql2/lib/packets/packet.js:712:17) at Query.execute (/node_modules/mysql2/lib/commands/command.js:28:26) at Connection.handlePacket (/node_modules/mysql2/lib/connection.js:425:32) at PacketParser.onPacket (/node_modules/mysql2/lib/connection.js:75:12) at PacketParser.executeStart (/node_modules/mysql2/lib/packet_parser.js:75:16) at Socket.<anonymous> (/node_modules/mysql2/lib/connection.js:82:25) at Socket.emit (events.js:314:20) at addChunk (_stream_readable.js:298:12) at readableAddChunk (_stream_readable.js:273:9) at Socket.Readable.push (_stream_readable.js:214:10) at TCP.onStreamRead (internal/stream_base_commons.js:188:23) { code: 'ER_WRONG_NAME_FOR_INDEX', errno: 1280, sqlState: '42000', sqlMessage: "Incorrect index name 'PRIMARY'", sql: 'ALTER TABLEadminsADD UNIQUE INDEXPRIMARY(id)', parameters: undefined }, original: Error: Incorrect index name 'PRIMARY' at Packet.asError (/node_modules/mysql2/lib/packets/packet.js:712:17) at Query.execute (/node_modules/mysql2/lib/commands/command.js:28:26) at Connection.handlePacket (/node_modules/mysql2/lib/connection.js:425:32) at PacketParser.onPacket (/node_modules/mysql2/lib/connection.js:75:12) at PacketParser.executeStart (/node_modules/mysql2/lib/packet_parser.js:75:16) at Socket.<anonymous> (/node_modules/mysql2/lib/connection.js:82:25) at Socket.emit (events.js:314:20) at addChunk (_stream_readable.js:298:12) at readableAddChunk (_stream_readable.js:273:9) at Socket.Readable.push (_stream_readable.js:214:10) at TCP.onStreamRead (internal/stream_base_commons.js:188:23) { code: 'ER_WRONG_NAME_FOR_INDEX', errno: 1280, sqlState: '42000', sqlMessage: "Incorrect index name 'PRIMARY'", sql: 'ALTER TABLEadminsADD UNIQUE INDEXPRIMARY(id)', parameters: undefined }, sql: 'ALTER TABLEadminsADD UNIQUE INDEXPRIMARY(id)', parameters: undefined }

When I clean all 'PRIMARY' records on migration, I don't get that error.

And I think it should be repaired because I'm using this tool with sequelize-auto to generate the models, and it generates this index explicitly. So both wouldn't be compatible.

I'm using this version: sequelize-auto-migrations@1.0.3 (git+https://github.com/flexxnn/sequelize-auto-migrations.git#0c3b385fffa474b2db825a2b48ce0873a8b9286b)