我正在尝试使用我的node.js项目中的sequelize来播种数据。
我得到的错误是:
未处理拒绝TypeError:Vacation.create不是函数
我的节点js app包含:
Vacation = require('./models/vacation.js');
var app = express();
var Sequelize = require('sequelize');
sequelize.sync().then(function () {
Vacation.create({
// insert new user
name: 'Hood River Day Trip',
slug: 'hood-river-day-trip',
category: 'Day Trip',
sku: 'HR199',
description: 'Spend a day sailing on the Columbia and ' +
'enjoying craft beers in Hood River!',
priceInCents: 9995,
tags: ['day trip', 'hood river', 'sailing', 'windsurfing', 'breweries'],
inSeason: true,
maximumGuests: 16,
available: true,
packagesSold: 0
},
{
name: 'Oregon Coast Getaway',
slug: 'oregon-coast-getaway',
category: 'Weekend Getaway',
sku: 'OC39',
description: 'Enjoy the ocean air and quaint coastal towns!',
priceInCents: 269995,
tags: ['weekend getaway', 'oregon coast', 'beachcombing'],
inSeason: false,
maximumGuests: 8,
available: true,
packagesSold: 0,
},
{
name: 'Rock Climbing in Bend',
slug: 'rock-climbing-in-bend',
category: 'Adventure',
sku: 'B99',
description: 'Experience the thrill of rock climbing in the high desert.',
priceInCents: 289995,
tags: ['weekend getaway', 'bend', 'high desert', 'rock climbing', 'hiking', 'skiing'],
inSeason: true,
requiresWaiver: true,
maximumGuests: 4,
available: false,
packagesSold: 0,
notes: 'The tour guide is currently recovering from a skiing accident.'
}).success(function (data) {
console.log(data.values)
})
});
和我的模型vacation.js包含
var Sequelize = require('sequelize');
module.exports = function (sequalize) {
var Vacation = sequelize.define("Vacation", {
name: Sequelize.STRING,
slug: Sequelize.STRING,
category: Sequelize.STRING,
sku: Sequelize.STRING,
description: Sequelize.STRING,
priceInCents: Sequelize.INTEGER,
tags: [Sequelize.STRING],
inSeason: Sequelize.BOOLEAN,
available: Sequelize.BOOLEAN,
requiresWaiver: Sequelize.BOOLEAN,
maximumGuests: Sequelize.INTEGER,
notes: Sequelize.STRING,
packagesSold: Sequelize.INTEGER,
});
return {
Vacation: Vacation
};
};
答案 0 :(得分:0)
vacation.js
导出并具有Vacation
属性的对象。这意味着导入:
Vacation = require('./models/vacation.js');
接收一个具有Vacation
属性但没有create
属性的对象。
您应该直接导出Vacation
:
<强> vacation.js 强>
module.exports = function(sequelize) {
var Vacation = sequelize.define('Vacation', {
// Model field definitions
});
return Vacation;
};