sequelize-auto icon indicating copy to clipboard operation
sequelize-auto copied to clipboard

MySQL fields with type BIT and default will be converted to Boolean with a default string

Open revyTH opened this issue 7 years ago • 1 comments

Consider the following MYSQL table:

CREATE TABLE `test` (  
  `flag` bit(1) NOT NULL DEFAULT b'0'  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

The field flag will be exported as the following:

'accountable': {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      defaultValue: '0',
}

As you can see the defaultValue is a string, but it should be a Number, like:

'accountable': {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      defaultValue: 0,
}

Otherwise creating the table (not specifying the field, thus using the default) will lead to error:

SequelizeDatabaseError: Data too long for column 'flag' at row 1

revyTH avatar Nov 28 '19 10:11 revyTH

Fixed in [email protected]

steveschmitt avatar Jul 17 '20 07:07 steveschmitt