typeorm: [PROBLEM] constraint "PRIMARY KEY" of relation "TABLE" does not exist
Issue type:
[x] question [ ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ ] latest
[x] @next
[ ] 0.x.x (or put your version here)
Question I want to use repository to find my sample data in postgres but i’m stuck !!
Example Files User.ts
@Entity()
export class User {
@PrimaryGeneratedColumn()
userid: number;
@Column()
usermail: string;
}
My Problem { QueryFailedError: constraint “PK_04d500b286ce3e4c4cbc20d97ea” of relation “user” does not exist at new QueryFailedError (C:\Users\develop\Desktop\TypeORM\src\error\QueryFailedError.ts:7:9) at Query.callback (C:\Users\develop\Desktop\TypeORM\src\driver\postgres\PostgresQueryRunner.ts:175:30) at Query.handleError (C:\Users\develop\Desktop\TypeORM\node_modules\pg\lib\query.js:142:17) at Connection.connectedErrorMessageHandler (C:\Users\develop\Desktop\TypeORM\node_modules\pg\lib\client.js:160:17) at Connection.emit (events.js:182:13) at Connection.EventEmitter.emit (domain.js:442:20) at Socket.<anonymous> (C:\Users\develop\Desktop\TypeORM\node_modules\pg\lib\connection.js:125:12) at Socket.emit (events.js:182:13) at Socket.EventEmitter.emit (domain.js:442:20) at addChunk (_stream_readable.js:283:12) message: ‘constraint “PK_04d500b286ce3e4c4cbc20d97ea” of relation “app” does not exist’,
I think this is PROBLEM ALTER TABLE “user” DROP CONSTRAINT “PK_04d500b286ce3e4c4cbc20d97ea”
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 19 (4 by maintainers)
Same here as @ZoroSC stated. Disabling
synchronizeoption resolved the issueVersions: TypeORM: 0.2.17 pg: 9.5.16
Its coming from migrations @vlapo . We need to improvise the queries generated via migrations. Just need to add extra bit of checking drop table / constraints if exists
I’m getting same error while starting my project using command “yarn start:debug” (using nestjs). I’m having a many-to-many relation between products and categories. My product entity is as follows:
@ManyToMany(type => Category) @JoinTable({ name: 'products_categories', joinColumn: { name: 'productId' }, inverseJoinColumn: { name: 'categoryId' }, }) category: Category[];Disabling synchronize isn’t an appropriate solution. I don’t understand why is it trying to drop constraint and even if it does then it should use “if exists”
@pleerock @MrJim-06 @Kononnable
@Kononnable
DROP CONSTRAINT IF EXISTSinstead of justDROP CONSTRAINTis one possible solution to this, only for pg 9.0+.I’m also having an issue with this same thing, and it seems to be throwing cause I’m using the synchronize option as seen here.
With my one entity looking like this:
Versions: TypeORM: 0.2.16 pg: 7.9.0
I think I’ve met similar or same issue. In my project I have NestJS + Typeorm + Postgres and bunch of migrations. One of these migrations creates a table with a custom PK constraint name:
So, if I run migrations and then
nest start --watchthe app I get an error:and this constraint definitely does not exist, because this constraint has custom name
my_table_pkin migration files. For some unknown reasons typeorm (?) tries to use another name for the constraint.If I just
nest startmy application with fresh empty DB, it starts without errors and I see DB with tables and so on, although I didn’t run migrations. Moreover, the custom constraint in that case has name PK_5f3350bd9b6c92a62a2257730b7 which is exactly as it was in the error. But that case is not appropriate for me, because migration with custom name is already in prod, so I can’t reverse it, and because there are some other differences with requirements (e.g. wrong column type for other column)Any ideas how it can be fixed? It works with synchronize false, but it seems to me like a just workaround, isn’t it?