当前位置: 动力学知识库 > 问答 > 编程问答 >

postgresql - Sequelize throwing unique constraint validation for a 'serial' column

问题描述:

I am doing a bulk insert (auto-setting up a test DB with pre-filling of data) and upon the first try of SomeModel.create() I get this error:

{[SequelizeUniqueConstraintError: Validation error]

name: 'SequelizeUniqueConstraintError',

message: 'Validation error',

errors:

[ { message: 'id must be unique',

type: 'unique violation',

path: 'id',

value: '1' } ],

fields: { id: '1' }}

Any next insert try on the model works fine. Checked this post and I guess it's the Postgres' "habit of not resetting the next number in the sequence after bulk inserts". I checked this post also, but from what I got as information there - I could not fix my problem. The ID columns in my models are BIGSERIAL, so I guess the auto-increment should work correctly? An example of table creation in my SQL code:

CREATE TABLE "account" (

"id" BIGSERIAL PRIMARY KEY NOT NULL,

...

)

and the Sequelize model declaration:

attributes: {

id: {

type: Sequelize.BIGINT,

allowNull: false,

primaryKey: true,

autoIncrement: true

},

...

分享给朋友:
您可能感兴趣的文章:
随机阅读: