FK问题 [英] FK issue
问题描述
我设置了如下FK
ALTER TABLE lk_sub_con ADD FOREIGN KEY(type)REFERENCES
lk_sort_of_contact(type_code);
但是当我这样做时
INSERT INTO lk_sort_of_contact(type_code)VALUES(''1'')(即:一个NULL进入
FK)它的工作原理
这是一个错误吗?
------------- --------------(广播结束)---------------------------
提示3:如果通过Usenet发布/阅读,请发送适当的
subscribe-nomail命令到 ma ******* @ postgresql.org 以便您的
消息可以干净地通过邮件列表
I have set up a FK as follows
ALTER TABLE lk_sub_con ADD FOREIGN KEY (type) REFERENCES
lk_sort_of_contact(type_code);
However when I do this
INSERT INTO lk_sort_of_contact (type_code) VALUES (''1'') (ie: a NULL into
the FK) it works
Is this a bug?
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly
推荐答案
mike< mi ** @bristolreccc.co.uk>写道:
mike <mi**@bristolreccc.co.uk> writes:
我已经设置了如下FK
ALTER TABLE lk_sub_con ADD FOREIGN KEY(type)REFERENCES
lk_sort_of_contact(type_code);
但是当我这样做时
INSERT INTO lk_sort_of_contact(type_code)VALUES(''1'')(即:一个NULL进入FK)它的工作原理<这是一个bug吗?
I have set up a FK as follows
ALTER TABLE lk_sub_con ADD FOREIGN KEY (type) REFERENCES
lk_sort_of_contact(type_code);
However when I do this
INSERT INTO lk_sort_of_contact (type_code) VALUES (''1'') (ie: a NULL into
the FK) it works
Is this a bug?
No.
引用列时允许使用NULL,除非列是
声明NOT NULL。
-Doug
---------- -----------------(广播结束)---------------------------
提示1:订阅和取消订阅命令转到 ma ******* @ postgresql.org
No.
NULLs are permitted in referencing columns unless that column is
declared NOT NULL.
-Doug
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org
mike< mi ** @ bristolreccc.co.uk>写道:
mike <mi**@bristolreccc.co.uk> writes:
我已经设置了如下FK
ALTER TABLE lk_sub_con ADD FOREIGN KEY(type)REFERENCES
lk_sort_of_contact(type_code);
但是当我这样做时
INSERT INTO lk_sort_of_contact(type_code)VALUES(''1'')(即:一个NULL进入FK)它的工作原理<这是一个bug吗?
I have set up a FK as follows
ALTER TABLE lk_sub_con ADD FOREIGN KEY (type) REFERENCES
lk_sort_of_contact(type_code);
However when I do this
INSERT INTO lk_sort_of_contact (type_code) VALUES (''1'') (ie: a NULL into
the FK) it works
Is this a bug?
No.
引用列时允许使用NULL,除非列是
声明NOT NULL。
-Doug
---------- -----------------(广播结束)---------------------------
提示1:订阅和取消订阅命令转到 ma ******* @ postgresql.org
No.
NULLs are permitted in referencing columns unless that column is
declared NOT NULL.
-Doug
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org
----- BEGIN PGP签名消息-----
哈希:SHA1
2004年6月10日星期四上午08:21,mike写道:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thursday 10 June 2004 08:21 am, mike wrote:
我已经设置了如下FK
ALTER表lk_sub_con ADD FOREIGN KEY(类型)参考
lk_sort_of_contact(type_code);
但是当我这样做时
INSERT INTO lk_sort_of_contact(type_code)VALUES(''1 '')(即:一个NULL进入FK)它的工作原理
这是一个bug吗?
I have set up a FK as follows
ALTER TABLE lk_sub_con ADD FOREIGN KEY (type) REFERENCES
lk_sort_of_contact(type_code);
However when I do this
INSERT INTO lk_sort_of_contact (type_code) VALUES (''1'') (ie: a NULL into
the FK) it works
Is this a bug?
No.
你有一张桌子lk_sub_con。那个表分配了外键。
这意味着你输入lk_sort_of_contact并不重要,重要的是
你把它放入lk_sub_con。
外键说像
"如果你把一个值放到表lk_sub_con的字段类型中,那么表lk_sort_of_contact字段中必须有相同的值
type_code"
尝试向lk_sub_con.type添加空值 - 或者不在
lk_sort_of_contact中的任何值。 Postgres会抛出一个错误。
如果你不想在引用的表lk_sort_of_contact中想要空值,你必须在那里定义那个
。也许你使字段type_code唯一或主要
键。
UC
- -
开源解决方案4U,LLC 2570 Fleetwood Drive
电话:+1 650 872 2425 San Bruno,CA 94066
Cell:+1 650 302 2405美国
传真:+1 650 872 2417
-----开始PGP签名-----
版本:GnuPG v1 .2.3(GNU / Linux)
iD8DBQFAyIY4jqGXBvRToM4RArWZAJwLGsUpEwCgPTybCbmkIE 52op1fmwCfWrfl
44hCrMlGYIaL8AvTXzeR7VI =
= yMO4
- ----结束PGP SIGNATURE -----
---------------------------(结束广播)---------------------------
提示1:订阅和取消订阅命令转到 ma ******* @ postgresql.org
No.
you have a table lk_sub_con. That table has the foreign key assigned.
This means it doesn''t matter what you put into lk_sort_of_contact , it matters
what you put into lk_sub_con.
The foreign key says something like
"If you put a value into field type of table lk_sub_con, the same value must
be existant in table lk_sort_of_contact field type_code"
Try to add a null value to lk_sub_con.type - or any value that''s not in
lk_sort_of_contact. Postgres will throw an error.
If you don''t want nulls in the referenced table lk_sort_of_contact you haveto
define that there. Maybe you make the field type_code unique or the primary
key.
UC
- --
Open Source Solutions 4U, LLC 2570 Fleetwood Drive
Phone: +1 650 872 2425 San Bruno, CA 94066
Cell: +1 650 302 2405 United States
Fax: +1 650 872 2417
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFAyIY4jqGXBvRToM4RArWZAJwLGsUpEwCgPTybCbmkIE 52op1fmwCfWrfl
44hCrMlGYIaL8AvTXzeR7VI=
=yMO4
-----END PGP SIGNATURE-----
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org
这篇关于FK问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!