Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2007

    Unanswered: Problems with references and foreign key in PSQL

    I get this error when I try to references to the table meta_host_types:

    there is no unique constraint matching given keys for referenced table "meta_host_types"

    the table looks like this:

    Table "public.meta_host_types"
    Column | Type | Modifiers
    id | integer | not null default nextval('meta_types_application_id_seq'::regclass)
    application | integer |
    value | text |
    comments | text |
    types | text |
    "meta_types_application_pkey" PRIMARY KEY, btree (id)
    "meta_host_types_id_key" UNIQUE, btree (id)
    "meta_host_types_value_key" UNIQUE, btree (value, application)
    Foreign-key constraints:
    "meta_types_application_application_fkey" FOREIGN KEY (application) REFERENCES appsmarteye(id)

    Whats the problem??

    Can someone please help!

    here are the code for the two tables:

    Here is the code for the meta_host_types table:

    bellus=# create table meta_host_types(id serial,application integer references appsmarteye,
    types text,
    value text,
    comments text,
    PRIMARY KEY(id));

    -------end of meta_host_types table--------------------

    Here are the code for the table that I want to be a references to the meta_host_types table:

    bellus=# create table host_application_definition(id serial,type_value integer references meta_host_types,
    connection_value integer references meta_connection_methods,
    group_value integer references meta_host_grouptypes,
    application_value integer references meta_host_types(application),PRIMARY KEY(id)

    really need help!!!

  2. #2
    Join Date
    May 2005
    San Antonio, Texas
    you've given the table you want it to reference but not the column.

    if you host_application_definition table try this for the reference:

    integer reference meta_host_types(id)

    You have to describe how it references it because postgres does not assume you mean the 'id' column.

    edit: I am not sure why you have: application_value integer references meta_host_types(application). It seems like you are trying to make two foreign keys with the same purpose. Just a curiosity.. you may have a purpose that I am just not aware of.
    Last edited by amthomas; 10-15-07 at 17:00.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts