gpt4 book ai didi

node.js - 关系不存在 - 带有 Postgres 适配器的 JugglingDB 出错

转载 作者:行者123 更新时间:2023-11-29 12:38:07 27 4
gpt4 key购买 nike

我正在将 Node 与 Express 结合使用,并将我的 ORM 从 Mongoose (Mongo) 转移到 JugglingDB (Postgres),并且很难让 JugglingDB 使用我定义的简单模式。

我的架构如下:

var UserToken = schema.define('UserToken', {
token: {type: String, index: true}
}, {
tablename: 'user_token'
});

var User = schema.define('User', {
email: {type: String, required: true, index: true},
password_hash: String,
first_name: String,
last_name: String,
role: {type: String, required: true, default: 'member'},
language: {type: String, default: 'en'},
api_key: String,
active: {type: Boolean, required: true, default: true},
confirmed: Date,
created: {type: Date, default: function() { return new Date() }},
modified: Date
}, {
tablename: 'users'
});

UserToken.belongsTo(User, {as: 'user', foreignKey: 'userId'});

// Define the schema in the DB if it is not there
schema.isActual(function(err, actual) {
if (!actual) {
schema.autoupdate();
}
});

尝试启动 Node 时出现以下错误:

{ [error: relation "UserToken" does not exist]
name: 'error',
severity: 'ERROR',
code: '42P01',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
file: 'namespace.c',
line: '407',
routine: 'RangeVarGetRelidExtended' }
{ [error: relation "User" does not exist]
name: 'error',
severity: 'ERROR',
code: '42P01',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
file: 'namespace.c',
line: '407',
routine: 'RangeVarGetRelidExtended' }

你能告诉我我缺少什么吗?感谢您的帮助!

最佳答案

使用表属性指定表名,如下所示:

var Organization = schema.define('Organization', {
name: String,
slug: String,
link: String
}, {
table: 'organizations'
});

关于node.js - 关系不存在 - 带有 Postgres 适配器的 JugglingDB 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18747931/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com