kmilo93sd
kmilo93sd

Reputation: 901

database error on simple select with sequelize

I have a simple query to my postgres database, is a simple select to a user by email. Im using node.js with express.js and sequelize.

i dont know why is throwing me an error, and the message is very bad, this is the error:

"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\" = '[email protected]' 
LIMIT 1;"
            },

this is my user model:

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

module.exports = User;

this is my sequelize config:

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
    }
  }
);

and this is my sql:

CREATE TABLE "users" (
    "id" varchar(36) NOT NULL,
    "email" varchar(30) NOT NULL UNIQUE,
    "password" varchar(200) NOT NULL,
    "created_at" TIMESTAMP NOT NULL,
    "updated_at" TIMESTAMP NOT NULL,
    CONSTRAINT users_pk PRIMARY KEY ("id")
) WITH (
  OIDS=FALSE
);

how can i fix this, and what is this error?

Upvotes: 0

Views: 1938

Answers (1)

tgo
tgo

Reputation: 1545

42P01error in postgresql is UNDEFINED TABLE. So the table doesn't exist on your server. You are trying to SELECT from an unexisting table.

Upvotes: 4

Related Questions