I work at the moment on a personal project. I'm using React.js for the front-end and Express.js and PostgreSQL for the back-end. When I'm trying to register an user in the database, I want the details to be written in 2 tables: 'users'(for generic user details) and 'login'(for keeping user's login details). On the server side I'm trying to achieve this with EXPRESS.js and KNEX query builder npm package to connect to PostgreSQL database. The following code should give a better picture of things:
db.transaction(trx => {
trx.insert({
email: email,
hash: hash
})
.into('login')
.returning('email')
.then(loginEmail => {
return trx('users')
.returning('*')
.insert({
email: loginEmail[0].email,
name: name,
joined: new Date()
})
.then(user => {
res.json(user[0]);
})
})
.then(trx.commit)
.catch(trx.rollback)
})
.catch(err => res.status(400).json(err));
});
After running the app and trying to register an user I recieve the following error back:
{"length":104,"name":"error","severity":"ERROR","code":"42P01","position":"13","file":"parse_relation.c","line":"1384","routine":"parserOpenTable"}
I've checked this error online and got that the following issue is coming up only when a relation doesn't exist in the database at all it could be a mixed-case spelling issue when I created the 'login' table. I dropped the database and created a new one considering the solutions found on the internet and the app is returning the same error.
If anyone encountered with such error or similar case, the help would be very much appreciated!