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.

Boolean values not parsed properly to integer fields for MySQL

See original GitHub issue

What are you doing?

isPublic: {type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false}

// ---------
// Later on...

Model.create({key1: 'value1', key2: 'value2'})
//or...
Model.create({key1: 'value1', key2: 'value2', isPublic: true})

What do you expect to happen?

Record being created into the database with a proper converted default value to 0 or 1, since MySQL uses TINYINT(1) as the column type for boolean fields.

What is actually happening?

SequelizeDatabaseError: Incorrect integer value: 'false' for column 'isPublic' at row 1 SequelizeDatabaseError: Incorrect integer value: 'true' for column 'isPublic' at row 1

Dialect: mysql Dialect version: 2.6.0 Database version: 8.0.15 Sequelize version: 5.2.1 Tested with latest release: Yes

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

12reactions
nicolasgramlichcommented, Apr 16, 2019

Note if this helps anyone. I was still getting that error after upgrading from from 4.42.0 to 5.6.0. It resolved itself after also upgrading mysql2 from 1.4.2 to 1.6.5 and a fresh node modules nuke+install.

0reactions
WikiRikcommented, Oct 25, 2022

This should be resolved in v7 with #14505

Read more comments on GitHub >

github_iconTop Results From Across the Web

Which MySQL data type to use for storing boolean values
MySQL 5.0 manual clearly says a boolean value is either 1 or 0. The phrase "anything else is true " is not true....
Read more >
An Introduction to MySQL BOOLEAN Data Type
Summary: this tutorial shows you how to use MySQL BOOLEAN data type to store Boolean values, true and false. Introduction to MySQL BOOLEAN...
Read more >
How to Select the Right Data Types | Tutorial by Chartio
boolean : for boolean (true/false) values. Some databases (like MySQL) don't have boolean data type and instead convert boolean values into integers (1=TRUE, ......
Read more >
MySQL Tutorial :: 7.9 Using AUTO_INCREMENT
The AUTO_INCREMENT attribute can be used to generate a unique identity for new rows: CREATE TABLE animals ( id MEDIUMINT NOT NULL AUTO_INCREMENT, ......
Read more >
Types - Doctrine Database Abstraction Layer (DBAL)
Values retrieved from the database are always converted to PHP's integer type ... when your date format is weird and not parsed correctly...
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