I am trying to insert some values to my table called todo, i've Postico gui open, which I can see the table visually on my screen better. The insert query was successfully, base off the console.log, that states "Data insert successful", which it went off one time and ever since running again it's just been doing the "todo_task_key" error.
const express = require("express");
const app = express();
app.set("view engine", "ejs");
const { Client } = require("pg")
const client = new Client();
client.connect();
const dotenv = require("dotenv")
dotenv.config()
const credentials = {
user: process.env.PGUSER,
host: process.env.PGHOST,
database: process.env.PGDATABASE,
password: process.env.PGPASSWORD,
port: process.env.PGPORT
}
async function registerPerson(person) {
const query = `
INSERT INTO todo (task, status)
VALUES ('Clean Kitchen', 0)
RETURNING id
`;
// const values = [person.task, person.status];
// // return client.query(text, values);
client.query(query, (err, res) => {
if (err) {
console.error(err);
return;
}
console.log('Data insert successful');
client.end();
});
}
registerPerson();
A duplicate key error means that you have tried to insert a row with the same key value as some other row already indexed by the todo_task_key index.