相关疑难解决方法(0)

在postgres中重置自动增量计数器

我想强制一个表的自动增量字段为某个值,我试着用这个:

ALTER TABLE product AUTO_INCREMENT = 1453
Run Code Online (Sandbox Code Playgroud)

ALTER SEQUENCE product  RESTART WITH 1453;
ERROR:  relation "your_sequence_name" does not exist
Run Code Online (Sandbox Code Playgroud)

我是postgres的新手:(

我有一个表productIdname领域

sql postgresql reset auto-increment

195
推荐指数
13
解决办法
16万
查看次数

使用Sequelize构建,播种和销毁PostgreSQL以进行测试

我正在尝试为每个测试自动化构建,播种和销毁我的数据库。我正在使用PostgreSQL,Mocha和Sequelize。

我找到了一个库:sequelize-fixtures,使我步入正轨,但最终它非常不一致,有时会引发约束错误:Unhandled rejection SequelizeUniqueConstraintError: Validation error即使我对模型没有任何验证。

这是我进行测试的方式

const sequelize = new Sequelize('test_db', 'db', null, {
  logging: false,
  host: 'localhost',
  port: '5432',
  dialect: 'postgres',
  protocol: 'postgres'
})

describe('/auth/whoami', () => {
  beforeEach((done) => {
    Fixtures.loadFile('test/fixtures/data.json', models)
      .then(function(){
         done()
      })
  })

  afterEach((done) => {
    sequelize.sync({
      force: true
    }).then(() => {
      done()
    })
  })

  it('should connect to the DB', (done) => {
    sequelize.authenticate()
      .then((err) => {
        expect(err).toBe(undefined)
        done()
      })
  })

  it('should test getting a user', (done) => …
Run Code Online (Sandbox Code Playgroud)

testing postgresql mocha.js node.js sequelize.js

5
推荐指数
1
解决办法
1254
查看次数