TypeORM booleans use tinyint (4) instead of the standard tinyint (1)
See original GitHub issueIssue 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:
- Created 5 years ago
- Reactions:23
- Comments:12 (3 by maintainers)
Top Related StackOverflow Question
Ok, that’ll change
@Column({ width: 1 })to@Column("bool")/@Column("boolean").Though perhaps the default type for
column: booleanin a future release should be “boolean” instead of “tinyint”.You can use
@Column("bool")