我使用带有Postgres和Express的node-orm2在app start上创建表。我一直在筛选GitHub问题,但一直无法找出为什么没有创建其他列。我做错了什么?
启动没有表格的应用程序时的控制台输出:
[SQL/postgres] SELECT * FROM information_schema.tables WHERE table_name = 'user'
[SQL/postgres] CREATE TABLE "user" ("id" SERIAL, PRIMARY KEY ("id"))
model_user.js(应该创建5列,但只创建1列)
var bcrypt = require('bcrypt-nodejs');
module.exports = function(db, cb) {
return {
id: { type: 'serial', key: true}, // <------- only column that gets created
name: { type: 'text', size: 128 },
email: { type: 'text', size: 128 },
createdAt : { type: 'date', required: true, time: true },
password: { type: 'text', size: 128 },
}, {
hooks: {
beforeValidation: function () {
this.createdAt = new Date();
}
},
methods : {
generateHash: function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
},
validPassword: function(password) {
return bcrypt.compareSync(password, this.local.password);
}
} // end methods
};
} // end exports
config_db.js
var orm = require('orm');
var model_user = require('../models/model_user');
module.exports = function(app) {
var opts = {
database : "somedb",
protocol : "postgres",
host : "127.0.0.1",
port : 5432,
user : "someguy",
password : "",
query : {
pool : true,
debug : true,
strdates : false
}
};
app.use(orm.express(opts, {
define: function (db, models, next) {
models.user = db.define("user", model_user);
db.sync();
next();
}
}));
}