db:seed:all
私は今、1時間以上苦労してきましたが、ゆっくりとこれについて頭を悩ませています.
私は単純なモデルを持っています:
'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.