Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typeORM: "message": "Data type \"Object\" in \"..." is not supported by \"postgres\" database."

Given the following entity definition:

@Entity()
export class User extends BaseEntity {
  @Column({ nullable: true })
  name!: string | null;
  
  @Column()
  age!: number;
}

The following error appears:

typeORM:   "message": "Data type \"Object\" in \"User.name" is not supported by \"postgres\" database."

...

name: 'DataTypeNotSupportedError',
  message:
   'Data type "Object" in "User.name" is not supported by "postgres" database.' }

When looking at the build, I see that the metadata that's emitted by TS addresses it as object:

__decorate([
    typeorm_1.Column({ nullable: true }),
    __metadata("design:type", Object)
], User.prototype, "name", void 0);

What am I doing wrong?

like image 486
silicakes Avatar asked Oct 14 '20 09:10

silicakes


2 Answers

You need to provide a data type explicitly.

@Column({ type: 'varchar', nullable: true })
name: string | null;
like image 153
Emersson Cardim Mota Avatar answered Oct 23 '22 23:10

Emersson Cardim Mota


The issue stems from this part right here:

@Column({ nullable: true })
name!: string | null;

When creating a union type, the reflected type will be Object. An easy way to overcome it will be to do something like:

@Column({ nullable: true })
name?: string;
like image 43
silicakes Avatar answered Oct 23 '22 23:10

silicakes