sequelize throw error方言需要在快速js中明确定义

时间:2017-08-19 09:26:09

标签: node.js express sequelize.js

您好我正在尝试使用sequelize查找所有查询。但是它给出了错误:

错误:自v4.0.0起,需要明确提供方言     在新的Sequelize(/home/europa/public_html/wired-rest-apis/node_modules/sequelize/lib/sequelize.js:170:13)

下面是我的快递js / node js代码: -

  var Sequelize = require('sequelize');

    // db config
    var env = "dev";
    var config = require('./config.json')[env];
    var password = config.password ? config.password : null;

    // initialize database connection
    var sequelize = new Sequelize(
        config.database,
        config.user,
        config.password, {
            logging: console.log,
            define: {
                timestamps: false
            }
        }
    );

    app.get('/list_cars', function(req,res){

        const Image = sequelize.define('add_cars', {/* ... */})
        const Car = sequelize.define('car_images', {/* ... */})
        Car.hasMany(Image, {as: 'Images', foreignKey:'add_car_id'})
        Car.findAll({
         include: [{
         model: Image
         }]
       })  .success(function(cars) {
            console.log(cars);
         });

    });

1 个答案:

答案 0 :(得分:0)

确保你在config.json中使用dialect,

{
    "username" : "root",
    "password" : "root",
    "database" :"grijan",
    "host" : "localhost",
    "dialect" : "mysql",
    "name" : "add"
}