question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataTypeNotSupportedError when using "| null" type

See original GitHub issue

Issue type:

[x] bug report

Database system/driver:

[x] mysql

TypeORM version:

[x] latest

Steps to reproduce or a small repository showing the problem:

When I set one of my entity fields with | null, ex:

@Column({ name: "code", nullable: true })
public code?: string | null;

I am told

DataTypeNotSupportedError: Data type "Object" in "User.code" is not supported by "mysql" database.
    at new DataTypeNotSupportedError (/project/node_modules/typeorm/error/DataTypeNotSupportedError.js:16:28)
    at /project/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:73:27
    at Array.forEach (<anonymous>)
    at EntityMetadataValidator.validate (/project/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:70:36)
    at /project/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:41:74
    at Array.forEach (<anonymous>)
    at EntityMetadataValidator.validateMany (/project/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:41:25)
    at Connection.buildMetadatas (/project/node_modules/typeorm/connection/Connection.js:515:33)
    at Connection.<anonymous> (/project/node_modules/typeorm/connection/Connection.js:162:30)
    at step (/project/node_modules/typeorm/connection/Connection.js:32:23)

This is a problem for me as I use strictNullChecks (so ? only allows undefined) and use the difference as:

  • null === the field is null
  • undefined === i dont know the value of this field

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

55reactions
pleerockcommented, Jul 28, 2018

You need provide a data type explicitly. By default typeorm reads typeorm from type definition, e.g. : string, and string is reflected into String. But string|null is reflected into Object and we cannot determine type. So, what you should do is to specify type explicitly:

@Column({ type: "string", name: "code", nullable: true })
public code?: string | null;
21reactions
feimosicommented, Feb 24, 2020

"text" type worked for me

@Column({ type: 'text', nullable: true })
content!: string | null;
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeORM error - DataTypeNotSupportedError - Stack Overflow
Show activity on this post. This is the correct usage: @Column({ type: 'varchar', nullable: true }) username: string | undefined;.
Read more >
typeorm/typeorm - Gitter
Is typeorm incompatible with transpileOnly mode for TS? I receive this: DataTypeNotSupportedError: Data type "Object" in "Study.status" is not supported by ...
Read more >
DescribeParams = true raises Data type not supported error
I get "Data type is not supported". I fully understand that this works fine if I set DescribeParams to False, but in my...
Read more >
Entities - typeorm - GitBook
The example below will create id with int as type which you must manually assign ... nullable: boolean - Makes column NULL or...
Read more >
InfoSphere Information Server, Version 8.1 Fix Pack 1, fix list
SCD stage rejects rows with null type 2 fielDS when comparing between ... ODBC Enterprise: Data type not supported error thrown while ...
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