0

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?

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.