Migration 20250902230900-update-primary-keys/@nocobase/server (up) failed: Original error: Multiple primary key defined: Multiple primary key defined
{"level":"debug","message":"run core migrations(afterLoad)","meta":{},"module":"application","submodule":"","method":"","app":"main","reqId":"b492aed6-ef29-47d8-b379-15bafd8f98c9","dataSourceKey":"main","timestamp":"2025-10-03 12:25:45"}
app-1 | {"level":"debug","message":"Executing (default): SHOW FULL COLUMNS FROM `migrations`;","app":"main","reqId":"b492aed6-ef29-47d8-b379-15bafd8f98c9","timestamp":"2025-10-03 12:25:45"}
app-1 | {"level":"debug","message":"Executing (default): SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME = 'migrations' AND TABLE_SCHEMA = 'sql_v3api_vietel'","app":"main","reqId":"b492aed6-ef29-47d8-b379-15bafd8f98c9","timestamp":"2025-10-03 12:25:45"}
app-1 | {"level":"debug","message":"Executing (default): SHOW INDEX FROM `migrations`","app":"main","reqId":"b492aed6-ef29-47d8-b379-15bafd8f98c9","timestamp":"2025-10-03 12:25:45"}
app-1 | {"level":"debug","message":"Executing (default): SHOW FULL COLUMNS FROM `migrations`;","app":"main","reqId":"b492aed6-ef29-47d8-b379-15bafd8f98c9","timestamp":"2025-10-03 12:25:45"}
app-1 | {"level":"debug","message":"Executing (default): SHOW INDEX FROM `migrations`","app":"main","reqId":"b492aed6-ef29-47d8-b379-15bafd8f98c9","timestamp":"2025-10-03 12:25:45"}
app-1 | {"level":"debug","message":"Executing (default): SELECT `name` FROM `migrations` AS `migrations` ORDER BY `migrations`.`name` ASC;","app":"main","reqId":"b492aed6-ef29-47d8-b379-15bafd8f98c9","timestamp":"2025-10-03 12:25:45"}
app-1 | {
app-1 | event: 'migrating',
app-1 | name: '20250902230900-update-primary-keys/@nocobase/server'
app-1 | }
app-1 | {"level":"debug","message":"Executing (default): ALTER TABLE `departments` CHANGE `id` `id` BIGINT NOT NULL PRIMARY KEY;","app":"main","reqId":"b492aed6-ef29-47d8-b379-15bafd8f98c9","timestamp":"2025-10-03 12:25:45"}
app-1 | {"level":"error","message":"Migration 20250902230900-update-primary-keys/@nocobase/server (up) failed: Original error: Multiple primary key defined","stack":"MigrationError: Migration 20250902230900-update-primary-keys/@nocobase/server (up) failed: Original error: Multiple primary key defined\n at /app/nocobase/node_modules/umzug/lib/umzug.js:170:27\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async Umzug.runCommand (/app/nocobase/node_modules/umzug/lib/umzug.js:126:20)\n at async Object.up (/app/nocobase/node_modules/@nocobase/server/lib/application.js:589:11)\n at async _AsyncEmitter.upgrade (/app/nocobase/node_modules/@nocobase/server/lib/application.js:798:5)\n at async _AppCommand.<anonymous> (/app/nocobase/node_modules/@nocobase/server/lib/commands/start.js:64:9)\n at async _AppCommand.parseAsync (/app/nocobase/node_modules/commander/lib/command.js:935:5)\n at async _AsyncEmitter.runAsCLI (/app/nocobase/node_modules/@nocobase/server/lib/application.js:611:23)","meta":{},"module":"application","submodule":"","method":"","app":"main","reqId":"b492aed6-ef29-47d8-b379-15bafd8f98c9","dataSourceKey":"main","timestamp":"2025-10-03 12:25:45"}
app-1 | {"level":"error","message":"Multiple primary key defined","stack":"Error\n at Query.run (/app/nocobase/node_modules/sequelize/lib/dialects/mysql/query.js:52:25)\n at sequelize.dialect.Query.run (/app/nocobase/node_modules/@nocobase/database/lib/database.js:413:20)\n at /app/nocobase/node_modules/sequelize/lib/sequelize.js:315:28\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async _update_primary_keys_default.up (/app/nocobase/node_modules/@nocobase/server/lib/migrations/20250902230900-update-primary-keys.js:83:11)\n at async /app/nocobase/node_modules/umzug/lib/umzug.js:167:21\n at async Umzug.runCommand (/app/nocobase/node_modules/umzug/lib/umzug.js:126:20)\n at async Object.up (/app/nocobase/node_modules/@nocobase/server/lib/application.js:589:11)\n at async _AsyncEmitter.upgrade (/app/nocobase/node_modules/@nocobase/server/lib/application.js:798:5)\n at async _AppCommand.<anonymous> (/app/nocobase/node_modules/@nocobase/server/lib/commands/start.js:64:9)\n at async _AppCommand.parseAsync (/app/nocobase/node_modules/commander/lib/command.js:935:5)\n at async _AsyncEmitter.runAsCLI (/app/nocobase/node_modules/@nocobase/server/lib/application.js:611:23)","app":"main","reqId":"b492aed6-ef29-47d8-b379-15bafd8f98c9","timestamp":"2025-10-03 12:25:45"}
I tried delete the primary key
ALTER TABLE departments DROP PRIMARY KEY;
SHOW CREATE TABLE departments;
and got that:
CREATE TABLE `departments` (
`id` bigint NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
`title` varchar(255) DEFAULT NULL,
`is_leaf` tinyint(1) DEFAULT NULL,
`parent_id` bigint DEFAULT NULL,
`sort` bigint DEFAULT NULL,
`created_by_id` bigint DEFAULT NULL,
`updated_by_id` bigint DEFAULT NULL,
KEY `departments_updated_by_id` (`updated_by_id`),
KEY `departments_parent_id` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3
Then restart the docker, but it didn’t work ;(