使用sequelize进行简单选择时出现数据库错误

时间:2019-06-29 15:40:18

标签: node.js postgresql sequelize.js

我对我的postgres数据库有一个简单的查询,是通过电子邮件对用户的一个简单选择。我将node.js与express.js和sequelize一起使用。

我不知道为什么会向我抛出错误,并且消息非常糟糕,这是错误消息:

<p><span>piece of a puzzle</span></p>

<p><span>Planet</span> <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/pin.png"> <span>Earth</span></p>

这是我的用户模型:

"message": {
            "name": "SequelizeDatabaseError",
            "parent": {
                "name": "error",
                "length": 104,
                "severity": "ERROR",
                "code": "42P01",
                "position": "97",
                "file": "parse_relation.c",
                "line": "1180",
                "routine": "parserOpenTable",
                "sql": "SELECT \"id\", \"email\", \"password\", 
\"created_at\" AS \"createdAt\", \"updated_at\" AS \"updatedAt\" FROM 
\"users\" AS \"user\" WHERE \"user\".\"email\" = 'kmilo93sd@gmail.com' 
LIMIT 1;"
            },

这是我的续集配置:

const User = database.define('user',{
  id: {
    type: sequelize.STRING,
    primaryKey: true
  },
  email: sequelize.STRING,
  password: sequelize.STRING
});

module.exports = User;

这是我的SQL:

module.exports = new Sequelize(
  process.env.database_name,
  process.env.database_user,
  process.env.database_password,
  {
    host: process.env.database_host,
    dialect: process.env.database_dialect,
    define: {
      underscored: true
    },
    pool: {
      max: 5,
      min: 0,
      idle: 10000
    }
  }
);

我该如何解决,这是什么错误?

1 个答案:

答案 0 :(得分:1)

42P01在Postgresql中的错误是UNDEFINED TABLE。因此该表在您的服务器上不存在。您正在尝试从不存在的表中SELECT