Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
null value in column "name" in relation "restaurants" violates the not-null condition

I see that there are a bunch of same errors that were caused by PostgreSQL but this time I get this error when I try to perform POST action with express.js. Even though I do not leave the "name" field "null" I still somehow have the follow error; null value in column "name" in relation "restaurants" violates the not-null condition

 // create a restaurant
app.post("/api/v1/restaurants", async (req, res) => {

  console.log("req.body: ",req.body);

  try {
    const results = await db.query(
      "INSERT INTO restaurants (name, location, price_range) values ($1, $2, $3) returning *",
      [req.params.name, req.params.location, req.params.price_range]
    );

    console.log("results: ",results);

    res.status(201).json({
      status: "success",
      data: {
        restaurant: "mcdonalds",
      },
    });
  } catch (error) {
    console.log(error.message);
  }
});

I filled this values in my postman;

{
    "name":"Big Chefs",
    "location":"Istanbul",
    "price_range":5
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

the mistake was that I was trying to enter my input into the wrong request part. The correct way is so;

const results = await db.query(
          "INSERT INTO restaurants (name, location, price_range) values ($1, $2, $3) returning *",
          [req.body.name, req.body.location, req.body.price_range]
        );

Even though I feel silly for such a mistake, I leave the question here so whoever needs that can easily solve the issue

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!