首页 > 解决方案 > 如何在 Sequelize 中使用 Postgres 的 BIGSERIAL?

问题描述

我想在 Sequelize 模型中使用 PostgreSQL BIG SERIAL 类型作为 id。我该怎么做呢?我发现 Sequelize 在执行此操作时使用 SERIAL:

id: {
  type: Sequelize.INTEGER,
  primaryKey: true,
  autoIncrement: true // this converts INT to SERIAL for Postgres
},

但是如何使它成为 BIGSERIAL 呢?

标签: node.jsdatabasepostgresqlsequelize.js

解决方案


我想你的答案可以在这个 Github issue上找到。

本质上,只需设置:

type: Sequelize.BIGINT, 
primaryKey: true,
autoIncrement: true

来自PostgreSQL 文档

数据类型 serial 和 bigserial 不是真正的类型,而只是用于创建唯一标识符列的符号方便(类似于某些其他数据库支持的 AUTO_INCREMENT 属性)。


推荐阅读