Boolean values not parsed properly to integer fields for MySQL
See original GitHub issueWhat 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:
- Created 4 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Note if this helps anyone. I was still getting that error after upgrading from from
4.42.0
to5.6.0
. It resolved itself after also upgradingmysql2
from1.4.2
to1.6.5
and a fresh node modules nuke+install.This should be resolved in v7 with #14505