“SERIAL"处或附近的语法错误;仅使用自动增量

编程入门 行业动态 更新时间:2024-10-22 22:48:57
本文介绍了“SERIAL"处或附近的语法错误;仅使用自动增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在构建时遇到错误:

服务器因错误而无法启动:SequelizeDatabaseError: syntaxSERIAL"处或附近的错误

Server failed to start due to error: SequelizeDatabaseError: syntax error at or near "SERIAL"

仅当参数 autoIncrement=true 被赋予主键时才会出现此错误.

This error ONLY appears when the parameter autoIncrement=true is given to the primary key.

'use strict'; export default function(sequelize, DataTypes) { return sequelize.define('Ladder', { ladder_id: { type: DataTypes.UUID, allowNull: false, primaryKey: true, autoIncrement: true //<------- If commented it works fine }, ladder_name: { type: DataTypes.STRING(50), allowNull: false, unique: true }, ladder_description: { type: DataTypes.TEXT, allowNull: true }, ladder_open: { type: DataTypes.BOOLEAN, allowNull: false }, ladder_hidden: { type: DataTypes.BOOLEAN, allowNull: false }, ladder_creation_date: { type: DataTypes.DATE, allowNull: false }, ladder_fk_user: { type: DataTypes.INTEGER, allowNull: false }, ladder_fk_game: { type: DataTypes.UUID, allowNull: false }, ladder_fk_platforms: { type: DataTypes.ARRAY(DataTypes.UUID), allowNull: false } }, { schema: 'ladder', tableName: 'ladders' }); }

我有 Sequelize 3.30.4 和 postgreSQL 9.6.

I have Sequelize 3.30.4 and postgreSQL 9.6.

我希望 autoIncrement 为 true,因为我正在使用 postgreSQL uuid_generate_v4() 生成 UUID.

I want autoIncrement at true because I am generating the UUID with postgreSQL uuid_generate_v4().

推荐答案

这里不是常规的 sequelize 用户,但让我指出,在 postgreql 中对非顺序列使用 autoIncrement 不是正确的方法.Postgresql 不提供默认的 uuid 编号生成器,但可以轻松添加扩展 www.postgresql/docs/9.4/static/uuid-ossp.html.我相信你已经这样做了.

Not a regular sequelize user here but let me point out that using autoIncrement for non sequential column is not the right way in postgreql. Postgresql does not provide a default uuid number generator but an extension can be added easily www.postgresql/docs/9.4/static/uuid-ossp.html. I believev you have already done so.

下一步就是向我们提供 sequelize.fn 函数.

The next step then is to us the sequelize.fn function.

创建一个表示数据库函数的对象.这个可以用在搜索查询中,在 where 和 order 部分中,默认情况下列定义中的值.

Creates an object representing a database function. This can be used in search queries, both in where and order parts, and as default values in column definitions.

所以我们有

ladder_id: { type: DataTypes.UUID, allowNull: false, primaryKey: true, default: sequelize.fn('uuid_generate_v4') }

更多推荐

“SERIAL"处或附近的语法错误;仅使用自动增量

本文发布于:2023-10-14 21:59:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492335.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:增量   语法错误   SERIAL   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!