我试图创建一个节点,进行序列化,表示后端,并且我的数据库位于mysql 8中。我正在用邮递员测试路由。 我总是在邮递员那里得到的答复是
"error: SequelizeDatabaseError: Unknown column 'createdAt' in 'field list'"
我仔细检查了所有代码,并且在项目的任何文件中均未出现“ createdAt”。
编辑:
//config.json
"development": {
"username": "user",
"password": "Password",
"database": "library",
"host": "127.0.0.1",
"dialect": "mysql"
}
//route.js
users.post("/register", (req, res) => {
const today = new Date();
const userData = {
username: req.body.user_name,
password: req.body.password,
role: req.body.role,
created: today
}
User.findOne({
where: {
username: req.body.username
}
})
});
//connection.js
const sequelize = new Sequelize("library", "user", "Password",{
host: 'localhost',
dialect: "mysql",
operatorsAliases: false,
poll: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
});
//model.js
module.exports = db.sequelize.define(
"user",
{
id:{
type: Sequelize.INTEGER(11),
primaryKey: true,
autoIntrement: true
},
username:{
type: Sequelize.STRING(35),
allowNull: false,
unique: true
},
password: {
type: Sequelize.STRING(35),
allowNull: false
},
role:{
type: Sequelize.INTEGER(11)
},
created:{
type: Sequelize.DATE,
defaultValue: Sequelize.NOW
}
}
)
这可能是什么?