1

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();

Palm
  • 360
  • 2
  • 17

1 Answers1

-1

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.

gapsf
  • 634
  • 4
  • 8
  • yeah, then I changed up the values of the key, like I said it goes through the first time, but it doesn't show up on my database, and finally when I re run it with the same value it does that duplicate key error. i am confused on where to go from here – Palm Aug 21 '22 at 15:55
  • Did you check table's actual content with select * from todo with psql or pgadmin? – gapsf Aug 23 '22 at 05:14