typeorm / typeorm

ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
http://typeorm.io
MIT License
34.13k stars 6.29k forks source link

number in uuid type leads to primary duplicated key error #2930

Open creadicted opened 6 years ago

creadicted commented 6 years ago

Issue type: [x] bug report [x] feature request

Database system/driver: [x ] sqlite

TypeORM version: [ x] 0.2.7

I had a default entity that is extended from BaseEntity.

export class ExtendedEntity extends BaseEntity {
    @ApiModelProperty()
    @Column()
    @PrimaryGeneratedColumn('uuid')
    id: number;

I made the mistake to set the id to number even when i create a uuid. So it should have been:

    @PrimaryGeneratedColumn('uuid')
    id: string;

This lead to the odd behavior that i got always the error: QueryFailedError: ER_DUP_ENTRY: Duplicate entry '1fcdd674-5367-4414-af30-55e0c8c5fb40' for key 'PRIMARY' When I created an instance of this object. Also rollbacks during the migrations where not possible.

I know that I did the mistake but I found the behavior so odd that I thought i report it.

ColeTownsend commented 5 years ago

Also experienced this

could not create unique index "UQ_a103c174a1e8f7af67efc3646fa" Key (description)=<fakedecription> is duplicated.
TypeError: Cannot read property 'connect' of undefined
    at /Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresDriver.ts:640:25
    at new Promise (<anonymous>)
    at PostgresDriver.obtainMasterConnection (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresDriver.ts:639:16)
    at PostgresQueryRunner.connect (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:86:58)
    at PostgresQueryRunner.<anonymous> (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:156:55)
    at step (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:42:23)
    at Object.next (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:23:53)
    at /Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:17:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:13:12)
    at /Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:154:50
    at new Promise (<anonymous>)
    at PostgresQueryRunner.query (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:154:16)
    at SelectQueryBuilder.<anonymous> (/Users/coletownsend/Documents/gits/CopContests/api/src/query-builder/SelectQueryBuilder.ts:1899:43)
    at step (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/query-builder/SelectQueryBuilder.js:42:23)
    at Object.next (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/query-builder/SelectQueryBuilder.js:23:53)
TypeError: Cannot read property 'connect' of undefined
    at /Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresDriver.ts:640:25
    at new Promise (<anonymous>)
    at PostgresDriver.obtainMasterConnection (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresDriver.ts:639:16)
    at PostgresQueryRunner.connect (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:86:58)
    at PostgresQueryRunner.<anonymous> (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:156:55)
    at step (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:42:23)
    at Object.next (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:23:53)
    at /Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:17:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:13:12)
    at /Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:154:50
    at new Promise (<anonymous>)
    at PostgresQueryRunner.query (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:154:16)
    at SelectQueryBuilder.<anonymous> (/Users/coletownsend/Documents/gits/CopContests/api/src/query-builder/SelectQueryBuilder.ts:1899:43)
    at step (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/query-builder/SelectQueryBuilder.js:42:23)
    at Object.next (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/query-builder/SelectQueryBuilder.js:23:53)
TypeError: Cannot read property 'connect' of undefined
    at /Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresDriver.ts:640:25
    at new Promise (<anonymous>)
    at PostgresDriver.obtainMasterConnection (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresDriver.ts:639:16)
    at PostgresQueryRunner.connect (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:86:58)
    at PostgresQueryRunner.<anonymous> (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:156:55)
    at step (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:42:23)
    at Object.next (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:23:53)
    at /Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:17:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:13:12)
    at /Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:154:50
    at new Promise (<anonymous>)
    at PostgresQueryRunner.query (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:154:16)
    at SelectQueryBuilder.<anonymous> (/Users/coletownsend/Documents/gits/CopContests/api/src/query-builder/SelectQueryBuilder.ts:1899:43)
    at step (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/query-builder/SelectQueryBuilder.js:42:23)
    at Object.next (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/query-builder/SelectQueryBuilder.js:23:53)
TypeError: Cannot read property 'connect' of undefined
    at /Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresDriver.ts:640:25
    at new Promise (<anonymous>)
    at PostgresDriver.obtainMasterConnection (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresDriver.ts:639:16)
    at PostgresQueryRunner.connect (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:86:58)
    at PostgresQueryRunner.<anonymous> (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:156:55)
    at step (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:42:23)
    at Object.next (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:23:53)
    at /Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:17:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:13:12)
    at /Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:154:50
    at new Promise (<anonymous>)
    at PostgresQueryRunner.query (/Users/coletownsend/Documents/gits/CopContests/api/src/driver/postgres/PostgresQueryRunner.ts:154:16)
    at SelectQueryBuilder.<anonymous> (/Users/coletownsend/Documents/gits/CopContests/api/src/query-builder/SelectQueryBuilder.ts:1899:43)
    at step (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/query-builder/SelectQueryBuilder.js:42:23)
    at Object.next (/Users/coletownsend/Documents/gits/CopContests/api/node_modules/typeorm/query-builder/SelectQueryBuilder.js:23:53)
pleerock commented 5 years ago

Thanks for the report, looks like a small bug, it should respect "uuid" instead of column type.

jampajeen commented 4 years ago

Same issue, I remove dist folder and it is resolved.