【发布时间】:2016-03-16 11:30:40
【问题描述】:
我正在尝试将表中某一列的数据类型从 biginteger 更改为 varchar。
myproject-# \d+ product_awbstock
Table "public.product_awbstock"
Column | Type | Modifiers | Storage | Description
-------------------+--------------------------+-----------+---------+-------------
airwaybill_number | bigint | not null | plain |
used | boolean | not null | plain |
created | timestamp with time zone | not null | plain |
modified | timestamp with time zone | not null | plain |
Indexes:
"product_awbstock_pkey" PRIMARY KEY, btree (airwaybill_number)
"product_awbstock_used" btree (used)
我正在使用这个查询,也给出了错误。
alter table product_awbstock ALTER COLUMN airwaybill_number TYPE varchar(15);
错误:外键约束 “awbstock_id_refs_airwaybill_number_d438187b”无法实施
详细信息:关键列“awbstock_id”和“airwaybill_number”是 不兼容的类型:bigint 和字符变化。
【问题讨论】:
-
错误消息指出该列是从其他表中引用的。不同类型的列之间不能有引用。
-
您应该删除 product_awbstock.airwaybill_number 和 ?.awbstock_id 之间的约束
-
您还必须将其他表的列更改为 varchar。但是当前的 bigint 数据类型有什么问题?
-
@jarlh 需要将该字段更新为字母数字。
标签: sql postgresql ddl