我已经为此苦苦挣扎db:seed:all
了一个多小时,慢慢地我对此失去了理智。
我有一个简单的模型:
'use strict';
module.exports = function (sequelize, DataTypes) {
var Car = sequelize.define('Cars', {
name: DataTypes.STRING,
type: DataTypes.INTEGER,
models: DataTypes.INTEGER
}, {
classMethods: {
associate: function (models) {
// associations can be defined here
}
}
});
return Car;
};
这是在迁移中,并使用sequelize db:migrate
工作正常的数据库。
接下来我想通过种子文件插入 2 辆汽车。所以我运行了命令sequelize seed:create --name insertCars
并添加了bulkInsert
:
'use strict';
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.bulkInsert(
'Cars',
[
{
name: "Auris",
type: 1,
models: 500,
createdAt: Date.now(), updatedAt: Date.now()
},
{
name: "Yaris",
type: 1,
models: 500,
createdAt: Date.now(), updatedAt: Date.now()
}
]
);
},
down: function (queryInterface, Sequelize) {
}
};
现在,当我运行时,出现sequelize db:seed:all
以下错误:
Loaded configuration file "config\config.json".
Using environment "development".
== 20160510132128-insertCars: migrating =======
Seed file failed with error: Cannot read property 'name' of undefined
有人有运行这些播种机的经验吗?供您参考,这里是我的配置文件:
{
"development": {
"username": "mydbdude",
"password": "mydbdude",
"database": "Cars",
"host": "127.0.0.1",
"dialect": "mssql",
"development": {
"autoMigrateOldSchema": true
}
},
....other configs
}
编辑:来自 db:migrate 的输出
Sequelize [Node: 5.9.1, CLI: 2.4.0, ORM: 3.23.0]
Loaded configuration file "config\config.json".
Using environment "development".
No migrations were executed, database schema was already up to date.