Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Devops
  3. Question
Devops

What is causing error “ There is no unique constraint matching specific keys for referenced table?

Asked by Grace Duncan Jul 25, 2023 1.1K views 1 answer
Share

About this question

The example below hows the error: there is no unique constraint matching speicifc keys for the referenced table, and now I cant understand why the error occurs in this case.

BEGIN;
CREATE TABLE foo (
    name                VARCHAR(256) PRIMARY KEY
);
CREATE TABLE bar(
    pkey        SERIAL PRIMARY KEY,
    foo_fk      VARCHAR(256) NOT NULL REFERENCES foo(name), 
    name        VARCHAR(256) NOT NULL, 
    UNIQUE (foo_fk,name)
);
CREATE TABLE baz(   
    pkey            SERIAL PRIMARY KEY,
    bar_fk          VARCHAR(256) NOT NULL REFERENCES bar(name),
    name            VARCHAR(256)
);
COMMIT;

Running the code mentioned above shows the error. Can anybody tell the reason for the error.

Your answer

1 Answer

More Devops discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest DevOps Blogs

Guides, tips and career advice on DevOps from JanBask experts.