Reputation: 4547
I am trying to change the data type of one column in the table from biginteger to 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)
I am using this query, the error is also given.
alter table product_awbstock ALTER COLUMN airwaybill_number TYPE varchar(15);
ERROR: foreign key constraint "awbstock_id_refs_airwaybill_number_d438187b" cannot be implemented
DETAIL: Key columns "awbstock_id" and "airwaybill_number" are of incompatible types: bigint and character varying.
Upvotes: 1
Views: 1944
Reputation: 311
You should:
ALTER TABLE product_awbstock DROP CONSTRAINT product_awbstock_pkey;
ALTER TABLE ??? DROP CONSTRAINT awbstock_id_refs_airwaybill_number_d438187b;
ALTER TABLE product_awbstock ALTER COLUMN airwaybill_number TYPE varchar(15);
ALTER TABLE ??? ALTER COLUMN airwaybill_id TYPE varchar(15);
ALTER TABLE product_awbstock ADD CONSTRAINT product_awbstock_pkey PRIMARY KEY (airwaybill_number);
ALTER TABLE ??? ADD CONSTRAINT awbstock_id_refs_airwaybill_number_d438187b FOREIGN KEY (awbstock_id) REFERENCES product_awbstock (airwaybill_number);
Upvotes: 2