Sequelize 在创建时抛出 'id must be unique'

Sequelize throwing 'id must be unique' on create

Sequelize 库的新手。根据我的理解,'id' 是由 sequelize 自动创建的(这就是我在数据库中看到的)。但是,当我转到 'create' 一个对象时,它会抛出此错误:

    { [SequelizeUniqueConstraintError: Validation error]
  name: 'SequelizeUniqueConstraintError',
  message: 'Validation error',
  errors: 
   [ { message: 'id must be unique',
       type: 'unique violation',
       path: 'id',
       value: '1' } ],
  fields: { id: '1' } }

违规代码:

  db.Account.create({
    email: req.body.email,
    password: req.body.password,
    allowEmail: req.body.allowEmail,
    provider: 'local',
    role: 'user'
  })

通知 ID 未在任何地方指定,也未在我的模型定义中指定。如果我在 postgres admin 中 运行 它生成的查询也很好 运行:

INSERT INTO "Accounts" ("id","email","role","verifyCode","provider","cheaterScore","isBanned","allowEmail","updatedAt","createdAt") VALUES (DEFAULT,'cat69232@gmail.com','user','','local',0,false,false,'2016-01-27 04:31:54.350 +00:00','2016-01-27 04:31:54.350 +00:00') RETURNING *;

有什么我可能在这里遗漏的想法吗?

编辑:

postgres 版本:9.5 堆栈跟踪从这里开始: /node_modules/sequelize/lib/dialects/postgres/query.js:326

Postgres 习惯于在批量插入后不重置序列中的下一个数字(自动增量字段)。因此,如果您在 init 例程中或从 SQL 转储文件中处理任何 pre-filling 数据,那可能是您的问题。

看看这个 post https://dba.stackexchange.com/questions/65662/postgres-how-to-insert-row-with-autoincrement-id