sequelize / sequelize

Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB (v6), DB2 and DB2 for IBM i.
https://sequelize.org/
MIT License
29.43k stars 4.26k forks source link

Boolean values not parsed properly to integer fields for MySQL #10633

Closed nicolaspfernandes closed 5 years ago

nicolaspfernandes commented 5 years ago

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

gabegorelick commented 5 years ago

See https://github.com/sequelize/sequelize/issues/10600

sushantdhiman commented 5 years ago

:tada: This issue has been resolved in version 5.2.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

nicolasgramlich commented 5 years ago

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.

jabowery commented 3 years ago

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.

I'm still getting:

SequelizeDatabaseError: Incorrect integer value: 'false' for columnvocascan.roles.adminRightsat row 1 (trying to get vocascan running as a server) despite having done:

$ npm install sequelize@v6.6.5
$ npm install mysql2@v2.3.0

Perhaps that's because I don't have a clue as to what you meant by "fresh node modules nuke+install".

rajathongal commented 1 year ago

This issue still persists

fzn0x commented 1 year ago

This issue still persists

What is the ~Sequelize version~ Sequelize and mysql2 version you are using? can you give a reproducible example with Sequelize SSCCE?

WikiRik commented 1 year ago

This should be resolved in v7 with #14505