1

I have been trying to make an array of numbers in type orm in my User entity, but type orm keeps showing up this problem

The code

@Entity()
class User {
    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    username: string;

    @Column()
    password: string;

    @Column()
    points: number;

    @Column()
    time: number[];
};

And the error in terminal is it :

(node:25398) UnhandledPromiseRejectionWarning: DataTypeNotSupportedError: Data type "Array" in "User.time" is not supported by "postgres" database. at new DataTypeNotSupportedError (/home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/error/DataTypeNotSupportedError.js:7:28) at /home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:74:27 at Array.forEach () at EntityMetadataValidator.validate (/home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:71:36) at /home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:42:74 at Array.forEach () at EntityMetadataValidator.validateMany (/home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:42:25) at Connection.buildMetadatas (/home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/connection/Connection.js:498:33) at Connection. (/home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/connection/Connection.js:128:30) at step (/home/vinicius/www/Projects/Quizzer/backend/node_modules/tslib/tslib.js:141:27) (node:25398) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:25398) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

3 Answers 3

2

From this:

@Entity()
class User {
    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    username: string;

    @Column()
    password: string;

    @Column()
    points: number;

    @Column("int", { array: true })
    time: number[];
};

Hope it helps :)

Sign up to request clarification or add additional context in comments.

Comments

0

You can also make it like this

@Column({ type: 'simple-array' })
time: number[]
  

Comments

0

The array type is supported, but as per the documentation you have to explicitly mention that it is an array in such a way:

@Column("int", {array: True})
time: number[]

If you still get an error related to the default value, try using the following syntax.

@Column("int", {array: True, default: []})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.