2016-11-17 62 views
0

如果我在當前數據庫(management)上創建新模式,爲什麼它會抱怨跨數據庫引用?Postgres外鍵/模式問題

management=# create schema mgschema; 
CREATE SCHEMA 

management=# alter table clients add column task_id int null references mgschema.tasks.id; 
ERROR: cross-database references are not implemented: "mgschema.tasks.id" 

回答

1
alter table clients add column task_id int null references mgschema.tasks.id; 

在不正確的語法REFERENCES,你應該使用:

REFERENCES reftable [ (refcolumn) ] 
+0

謝謝,這麼瑣碎。 :o現在起作用。 –

+0

不客氣。 – McNets

1

簡單references只需要一個表名。外鍵然後將自動指向該表的主鍵,例如,

alter table clients add column task_id int null references mgschema.tasks; 

另一種方法是指定表和列,但不與單個標識符:如果目標表具有多個獨特的限制是需要

alter table clients add column task_id int null references mgschema.tasks (id); 

的第二格式。