我正在使用带有 Express 的 Node,并且正在将我的 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();
}
});
尝试启动节点时出现以下错误:
{ [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' }
你能告诉我我错过了什么吗?谢谢你的帮助!