Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda