Skip to content
New issue

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

Postgres - Error violation of foreign key constraint Address entity #2

Open
cdiban opened this issue May 4, 2023 · 0 comments
Open

Comments

@cdiban
Copy link

cdiban commented May 4, 2023

I want to share my experience using the migration tool. My database environment is PostgreSQL 14, and I had two problems.

First, when we run migrations, the script throws an error regarding FK violations related countryID into "Address" entity, because it is referring Region ID, but we need to add "Country" data into "Region" before creating this PK. Simply put, the value of FOREIGN KEY(address) provided in the ALTER statement is not present in the source (region) table.

So, to solve this problem we add the FK creation after step 3 like this.

// Run the data migrations function
await vendureV2Migrations(queryRunner);

await queryRunner.query(`ALTER TABLE "address" ADD CONSTRAINT "FK_d87215343c3a3a67e6a0b7f3ea9" FOREIGN KEY ("countryId") REFERENCES "region"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, undefined);

Second, in vendureV2Migrations function when set the currencyCode on all ProductVariantePrice entities based on the associated Channel, thows PSQLException: ERROR: operator does not exist: uuid = character varying

await q(
        `UPDATE "product_variant_price" SET "currencyCode" = (SELECT "defaultCurrencyCode" FROM "channel" WHERE "id" = "channelId")`
    );

Instead of putting the string "channelId" in the "WHERE" condition, I put the default channel code condition, but maybe this is not the traversal solution.

I hope this helps.

Best.
Carlo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant