2014-01-17 23 views
1

我在7周內通過7個數據庫。Column <tablename> _id引用外鍵找不到

在PostgreSQL中,我創建了一個包含SERIAL venue_id列的場地表。

輸出的

\d venues

         Table "public.venues" 
    Column  |   Type   |       Modifiers 
----------------+------------------------+----------------------------------------------------------- 
venue_id  | integer    | not null default nextval('venues_venue_id_seq'::regclass) 
name   | character varying(255) | 
street_address | text     | 
type   | character(7)   | default 'public'::bpchar 
postal_code | character varying(9) | 
country_code | character(2)   | 
Indexes: 
    "venues_pkey" PRIMARY KEY, btree (venue_id) 
Check constraints: 
    "venues_type_check" CHECK (type = ANY (ARRAY['public'::bpchar, 'private'::bpchar])) 
Foreign-key constraints: 
    "venues_country_code_fkey" FOREIGN KEY (country_code, postal_code) REFERENCES cities(country_code, postal_code) MATCH FULL 

下一步是創建引用一個外鍵venue_id事件表。

我想這一點:

CREATE TABLE events (
event_id SERIAL PRIMARY KEY, 
title text, 
starts timestamp, 
ends timestamp, 
FOREIGN KEY (venue_id) REFERENCES venues (venue_id)); 

而且我得到這個錯誤:

ERROR: column "venue_id" referenced in forgein key not found 

有什麼不對?

+0

顯示'\ d場所'的輸出。表格是否存在?它是否有名爲'venue_id'的列? –

+0

它存在,它有一個venue_id列作爲主鍵。我現在不在這臺機器上,所以我會在明天跟進。 – quantumpotato

+0

已添加到原始帖子 – quantumpotato

回答