Ada*_*ims 7 postgresql foreign-keys postgresql-9.5
在Postgres 9.5中尝试ALTER TABLE创建外键约束时:from product_template.product_brand_idtoproduct_brand.id
ALTER TABLE public.product_template
ADD CONSTRAINT product_template_product_brand_id_fkey
FOREIGN KEY (product_brand_id)
REFERENCES public.product_brand (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE SET NULL;
Run Code Online (Sandbox Code Playgroud)
返回错误
ERROR: insert or update on table "product_template" violates foreign key constraint "product_template_product_brand_id_fkey"
DETAIL: Key (product_brand_id)=(12) is not present in table "product_brand".
STATEMENT: ALTER TABLE "product_template" ADD FOREIGN KEY ("product_brand_id") REFERENCES "product_brand" ON DELETE set null
Run Code Online (Sandbox Code Playgroud)
林困惑,为什么Postgres的是试图找到product_brand.product_brand_id,当FKEY是product_template.product_brand_id到product_brand.id
有任何想法吗?
错误消息只是指出表product_template中至少有一行包含12列中的值product_brand_id
但是表product_brand中没有对应的行id包含该列的值12
Key (product_brand_id)=(12)关联外键的源列,而不是目标列。
| 归档时间: |
|
| 查看次数: |
6759 次 |
| 最近记录: |