Reputation: 1100
I try to get two column values from my mysql database.
This is my model
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;
And, This is my route
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
}
});
});
I'm having the error, while getting the client_id and client_secret from the database.
My error
UPDATED : Database.js File
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
},
});
Upvotes: 1
Views: 17615
Reputation: 9308
Try adding primaryKey: true
to client_id
in AuthDetails
.
const AuthDetails = db.define('auth_details', {
client_id : {
type: Sequelize.STRING,
primaryKey: true
},
client_secret : {
type: Sequelize.STRING
}
},{
timestamps : false
});
I am guessing Sequelize considers id
as primary key by default unless it is specified and appending id
to findAll
query.
ref: https://github.com/sequelize/sequelize/issues/741
Upvotes: 5