Узел Js (Sequelize) - необработанное отклонение. SequelizeDatabaseError: Неизвестный столбец 'id' в 'списке полей' - PullRequest
0 голосов
/ 11 января 2019

Я пытаюсь получить два значения столбца из моей базы данных mysql.

Это моя модель

const Sequelize = require('sequelize');
const db = require('../config/database');

const AuthDetails = db.define('auth_details', {
    client_id : {
        type: Sequelize.STRING
    },
    client_secret : {
        type: Sequelize.STRING
    }
},{
    timestamps : false
});


module.exports = AuthDetails;

И, это мой маршрут

router.post('/login', (req, res, next) => {
// console.log(req.body);

   Users.findOne( { where : { mobile_number: req.body.mobile_number}})
  .then(users => {

  UserAuthDet.findAll({   
    where: {
      client_id: req.body.client_id,
      client_secret: req.body.client_secret
    }
  });
});

У меня ошибка при получении client_id и client_secret из базы данных.

Моя ошибка

enter image description here

ОБНОВЛЕНО: Файл Database.js

const Sequelize = require('sequelize');

module.exports = new Sequelize('mydbname', 'root', '', {
  host: 'localhost',
  dialect: 'mysql',
  operatorsAliases: false,

  pool: {
    max: 5,
    min: 0,
    acquire: 30000,
    idle: 10000
  },

});

1 Ответ

0 голосов
/ 11 января 2019

Попробуйте добавить primaryKey: true к client_id в AuthDetails.

const AuthDetails = db.define('auth_details', {
  client_id : {
    type: Sequelize.STRING,
    primaryKey: true
  },
  client_secret : {
    type: Sequelize.STRING
  }
},{
  timestamps : false
});

Я предполагаю, что Sequelize рассматривает id как первичный ключ по умолчанию, если он не указан и добавляет запрос id к findAll.

ref: https://github.com/sequelize/sequelize/issues/741

...