Skip to content

Unexpected default for generated entity #1917

@ltudisco

Description

@ltudisco

Describe the bug

Unexpected default for generated entity with boolean property

To Reproduce

Steps to reproduce the behavior:

  1. Create the following table in a mysql database
CREATE TABLE `test_table` (
  `test_column` tinyint(1) not null default 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Screenshot 2021-06-10 at 17 05 33

  1. Run the following script to autogenerate entities based on the database above

ts-node generateEntities.ts

import { MikroORM } from '@mikro-orm/core';


(async () => {
  const orm = await MikroORM.init({
    discovery: {
      // we need to disable validation for no entities 
      warnWhenNoEntities: false,
    },
    dbName: dbName
    ....
  });
  const generator = orm.getEntityGenerator();
  const dump = await generator.generate({
    save: true,
    baseDir: process.cwd() + '/my-entities',
  });
  console.log(dump);
  await orm.close(true);
})();

Expected behavior

I would expect the generated entity to have a boolean property defaulting to False but the property is actually defaulting to True.

This is the actual autogenerated entity

import { Entity, Property } from '@mikro-orm/core';

@Entity()
export class TestTable {

  @Property()
  testColumn: boolean = true;

}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions