How to select data from existing tables using sequelize

I already have tables in postgresql. I want to extract data from them using sequelize. I used several ways to do this. But still it is not possible to map db schma to continue in node.js.

  const Test = Conn.define('test', {
          race_id: 
          {
           type: Sequelize.STRING,
           allowNull: false   
           },
          race_name:
          {
           type: Sequelize.STRING,
           allowNull: false
          }
   });

  Conn.sync(); 
export default Conn;

I am defining a schema in node.js and have a table with the same schema in postgresql.

But when executed Db.models.test.findAll({ where: args });

The console displays the result as follows:

Execution (default): SELECT "id", "race_id", "race_name", "createdAt", "updatedAt" FROM "tests" AS "test";

And I will get one more conclusion, which

column \"id\" does not exist

I can’t understand why to retrieve data from the test table and retrieve columns that I don’t have.

sequelize? ORM .

+4
1

:

const Test = Conn.define('test', {
      race_id: 
      {
       type: Sequelize.STRING,
       allowNull: false,
       primaryKey: true
       },
      race_name:
      {
       type: Sequelize.STRING,
       allowNull: false
      }
});

id .

, .

+4

All Articles