TypeError: Cannot read property 'findAll' of undefined (expressjs)

前端 未结 4 1870
礼貌的吻别
礼貌的吻别 2021-01-03 07:16

TypeError: Cannot read property \'findAll\' of undefined (expressjs).

All functions (sequelize) are not working. All errors: Cannot rea

4条回答
  •  清酒与你
    2021-01-03 07:26

    You have created two instances of sequelize. One in models/index.js in line 12/14 and second instance in server script in line 19. And you start second instance, but in model you tried to use first instance.

    Your model/index.js file is ok. In your server file add

    var database = require('path/to/models');
    

    change your db start to:

    database.sequelize .authenticate() .then(function(err) { console.log('Connection has been established successfully.'); }, function (err) { console.log('Unable to connect to the database:', err); });

    And you have to pass 'database' object to your controllers instead of models = require('./../models'); and from your controllers you have access to your model : database.User

提交回复
热议问题