Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda