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

[MySQL] FK Referenced column cannot be a subset of a Unique / Primary Key #1608

Open
shubham-yb opened this issue Jul 2, 2024 · 0 comments
Labels
triage Needs to be triaged

Comments

@shubham-yb
Copy link
Contributor

In MySQL, you can reference a column which is the part of a Unique Key or a Primary Key for a Foreign Key. This is not allowed in YB / PG.

Workaround: The referenced columns will need to have individual Unique / Primary keys.

Example:

Sample schema on the source (allowed in MySQL):

create table k(id int,id2 int,UNIQUE KEY `uk_k` (`id`,`id2`));

create table h(id int,CONSTRAINT `fk_h` FOREIGN KEY (`id`) REFERENCES `k` (`id`));

Exported Schema:

CREATE TABLE h (
        id bigint
) ;
CREATE TABLE k (
        id bigint,
        id2 bigint
) ;
ALTER TABLE k ADD UNIQUE (id,id2);
ALTER TABLE h ADD CONSTRAINT fk_h FOREIGN KEY (id) REFERENCES k(id) MATCH SIMPLE ON DELETE NO ACTION ON UPDATE NO ACTION;

Error during import:

ERROR: there is no unique constraint matching given keys for referenced table "k"

Suggested Changes:

Add individual Unique / Primary keys to the referenced column.

@github-actions github-actions bot added the triage Needs to be triaged label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant