From 1f431dc2d6fd9d640cc7096cf3d6a73eddb28e7b Mon Sep 17 00:00:00 2001 From: chenos Date: Thu, 1 Dec 2022 10:00:46 +0800 Subject: [PATCH] fix(database): id is not generated when custom primary key --- packages/core/database/src/collection.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/database/src/collection.ts b/packages/core/database/src/collection.ts index 827396754..5902c8dbe 100644 --- a/packages/core/database/src/collection.ts +++ b/packages/core/database/src/collection.ts @@ -7,7 +7,7 @@ import { QueryInterfaceDropTableOptions, SyncOptions, Transactionable, - Utils, + Utils } from 'sequelize'; import { Database } from './database'; import { Field, FieldOptions } from './fields'; @@ -200,6 +200,10 @@ export class Collection< ); } + if (this.options.autoGenId !== false && options.primaryKey) { + this.model.removeAttribute('id'); + } + this.removeField(name); this.fields.set(name, field); this.emit('field.afterAdd', field);