question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Entering values as null but still getting error: TypeError: Bind parameters must not contain undefined. To pass SQL NULL specify JS null

See original GitHub issue

I’m trying to pass data from my app to mariadb via mysql2. The model method collects the data from the template via req.body.* and then the data presumably gets stored into a new instance of the class Car and that instance is console.logged and is supposed to be passed to the model/class method. When I try and submit the form data, I get the following error:

TypeError: Bind parameters must not contain undefined. To pass SQL NULL specify JS null

Here’s what’s being console.logged (the unneeded properties are ‘javascript nulls’):

Car {
  id: null,
  model_year: '2008',
  make: 'Chevrolet',
  model: 'Corvette',
  miles: '56000',
  color: 'red',
  transmission: 'automatic',
  layout: 'FR',
  engine_config: 'V8',
  car_photo_url: null,
  car_price: null
}

Here’s the controller method code:

exports.postAddVehicle = (req, res, next) => {
    //const id = null;
    const model_year = req.body.model_year;
    const make = req.body.make;
    const model = req.body.model;
    const miles = req.body.miles;
    const color = req.body.color;
    const transmission = req.body.transmission;
    const layout = req.body.layout;
    const engine_type = req.body.engine_config;
    // const car_photo_url = null;
    // const car_price = null;
    const car = new Car(
        null, model_year, make, model, 
        miles, color, transmission, layout, engine_type,
        null, null);
        console.log(car);
    car
        .save()
        .then(() => {
            res.redirect('/');
        })
        .catch(err => console.log(err))
}

So there are properties of the class that I don’t want to enter the data for right now so I set those properties to null but apparently mysql2 doesn’t see those properties as javascript nulls?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
sidorarescommented, Sep 15, 2021

as @dougwilson posted - the issue is that you set engine_config in your Car object but later use engine_type which is undefined

1reaction
sidorarescommented, Sep 14, 2021

if you can add console.log in mysql2 dependency in your node_modules just before line indicated in TypeError: Bind parameters must not contain undefined. To pass SQL NULL specify JS null stack you should be able to see what is actually passed and what missing ( and maybe print query your ORM has generated )

Read more comments on GitHub >

github_iconTop Results From Across the Web

MYSQL2 PROBLEM: TypeError: Bind parameters must not ...
This error is pretty much self explanatory. Bind parameters must not contain undefined. To pass SQL NULL specify JS null.
Read more >
Bind parameters must not contain undefined when passing an ...
TypeError : Bind parameters must not contain undefined. To pass SQL NULL specify JS null My code looks as follows: let insertQuery =...
Read more >
bind parameters must not contain undefined - You.com
MYSQL2 PROBLEM: TypeError: Bind parameters must not contain undefined. To pass SQL NULL specify JS null. Asked Nov 24, 2021 • 1 votes...
Read more >
Bind parameters must not contain undefined. To pass SQL ...
Coding example for the question MYSQL2 PROBLEM: TypeError: Bind parameters must not contain undefined. To pass SQL NULL specify JS null-node.js.
Read more >
MySQL NULL Values - IS NULL and IS NOT NULL - W3Schools
What is a NULL Value? A field with a NULL value is a field with no value. ... We will have to use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found