TypeORM booleans use tinyint (4) instead of the standard tinyint (1)

See original GitHub issue

Issue type: [x] bug report Database system/driver: [x] mysql / mariadb TypeORM version: [x] latest Steps to reproduce or a small repository showing the problem:

Create a entity modal with a boolean type and use it in MySQL.

@Entity()
export class Foo {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  isBar: boolean = false;
}

When you sync with the database you’ll find that the isBar column is equivalent to tinyint (4) because TypeORM uses tinyint as the type without a size.

However, the standard for booleans in MySQL is tinyint (1). MySQL has an official BOOL/BOOLEAN alias type, which is an alias to tinyint (1) not tinyint (4). And other ORMs properly use tinyint (1) for their booleans, e.g. I’m migrating a Doctrine based project to TypeORM and need to manually specify the widths of my booleans to avoid counterproductive migrations being created.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:23
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

17reactions
dantmancommented, Feb 12, 2019

You can use @Column("bool")

Ok, that’ll change @Column({ width: 1 }) to @Column("bool")/@Column("boolean").

Though perhaps the default type for column: boolean in a future release should be “boolean” instead of “tinyint”.

16reactions
rustamwincommented, Feb 12, 2019

You can use @Column("bool")

Read more comments on GitHub >

github_iconTop Results From Across the Web

Boolean vs tinyint(1) for boolean values in MySQL
It seems that MySQL transparently treats boolean as tinyint(1) . So you can use boolean , true and false and MySQL treats them...
Read more >
Why I Use TINYINT Columns Instead Of BIT ... - Ben Nadel
Neither BIT nor TINYINT is a "Boolean" value. We can only treat them as Boolean values when our developers agree to treat them...
Read more >
Entities - typeorm - GitBook
Default value is true . select: boolean - Defines whether or not to hide this column by default when making queries. When set...
Read more >
How is TINYINT(1) converted to BOOL/BOOLEAN?
Regarding the TRUE or FALSE , any int (int, tinyint, smallint, bigint) value can be used as (or converted to) a boolean value....
Read more >
TinyInt converted to Boolean whether or not it's used as one
In MySQL, tinyint(1) is a synonym for boolean. Even though values from -127 to 127 can be stored in it, when using SQL...
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