We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I tried to run the following migration using Typeorm:
await queryRunner.createTable( new Table({ name: 'Products', columns: [ { name: 'product_id', isPrimary: true, type: 'serial', }, { name: 'name', type: 'varchar', }, { name: 'main_product_id', type: 'int', isNullable: true, }, { name: 'created_at', type: 'timestamp with time zone', default: 'now()', }, { name: 'updated_at', type: 'timestamp with time zone', default: 'now()', }, { name: 'deleted_at', type: 'timestamp with time zone', isNullable: true, }, ], foreignKeys: [ { name: 'fk_Products_Products', columnNames: ['main_product_id'], referencedTableName: 'Products', referencedColumnNames: ['product_id'], onUpdate: 'CASCADE', onDelete: 'CASCADE', } ] }), true, )
pg-mem fails with the error:
there is no unique constraint matching given keys for referenced table "Products"
while real postgres works.
Analyzing the query generated by typeorm, I noticed the problem may be the order of the contraints.
The query generated by typeorm:
CREATE TABLE "public"."Products" ( "product_id" serial NOT NULL, "name" varchar NOT NULL, "main_product_id" int, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP WITH TIME ZONE, CONSTRAINT "fk_Products_Products" FOREIGN KEY ("main_product_id") REFERENCES "public"."Products" ("product_id") ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT "PK_6f8a5f1d7d708767d6945192758" PRIMARY KEY ("product_id") );
The modified version that does not fail on https://oguimbal.github.io/pg-mem-playground/:
CREATE TABLE "public"."Products" ( "product_id" serial NOT NULL, "name" varchar NOT NULL, "main_product_id" int, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP WITH TIME ZONE, CONSTRAINT "PK_6f8a5f1d7d708767d6945192758" PRIMARY KEY ("product_id"), CONSTRAINT "fk_Products_Products" FOREIGN KEY ("main_product_id") REFERENCES "public"."Products" ("product_id") ON DELETE CASCADE ON UPDATE CASCADE );
Both versions work on a real postgres.
3.0.4
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Describe the bug
I tried to run the following migration using Typeorm:
pg-mem fails with the error:
while real postgres works.
Analyzing the query generated by typeorm, I noticed the problem may be the order of the contraints.
To Reproduce
The query generated by typeorm:
The modified version that does not fail on https://oguimbal.github.io/pg-mem-playground/:
Both versions work on a real postgres.
pg-mem version
3.0.4
The text was updated successfully, but these errors were encountered: