【发布时间】:2019-08-21 00:17:42
【问题描述】:
我正在尝试使用 sequelize 从 html 表单导出数据并收到以下错误:无法读取未定义的属性“创建”。我能够从表单中输出对象中的数据就好了。
routes.js
var db = require("../models");
module.exports = function(app) {
app.post("/api/orders", function(req,res) {
console.log(req.body);
db.orders.create({
date: req.body.date,
billingAddress: req.body.billingAddress,
city: req.body.city,
state: req.body.state,
email: req.body.email,
cupcakeType: req.body.cupcakeType,
quantity: req.body.quantity,
specialInstructions: req.body.specialInstructions,
totalPrice: req.body.totalPrice,
card: req.body.card,
cardNumber: req.body.cardNumber,
cvc: req.body.cvc,
CustomerID: req.body.CustomerID
})
.then(function(dbOrders){
console.log(dbOrders);
res.json(dbOrders);
});
});
orders.js
module.exports = function(sequelize, DataTypes) {
var Orders = sequelize.define("Orders", {
date: {
type: DataTypes.DATEONLY,
allowNull: false
},
billingAddress: {
type: DataTypes.STRING,
allowNull: false,
},
city: {
type: DataTypes.STRING,
allowNull: false,
},
state: {
type: DataTypes.STRING,
allowNull: false,
},
email: {
type: DataTypes.STRING,
allowNull: false,
// validate: {
// isEmail: true
// }
},
希望在名为“cupcakes”的数据库和名为“orders”的表中创建帖子
【问题讨论】:
标签: node.js sequelize.js mysql2