Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > PostgreSQL > Problems with references and foreign key in PSQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-15-07, 09:36
bellus bellus is offline
Registered User
 
Join Date: Oct 2007
Posts: 2
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 |
Indexes:
"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!!!
Reply With Quote
  #2 (permalink)  
Old 10-15-07, 17:55
amthomas amthomas is offline
Registered User
 
Join Date: May 2005
Location: San Antonio, Texas
Posts: 134
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 18:00.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On