I'm currently stuck in a catch 22 with my Django Application. I have to change the type of a column from Varying char to Integer as i'm moving from UUID's to plain old ID's (the data is not changing ever as it's physical constants). Now django threw a Fit originally about not being able to cast from VarChar to Int, so i "helped" it out with:
ALTER TABLE glass_fill ALTER COLUMN id TYPE INTEGER USING CAST(id AS INT);
Now, it says:
django.db.utils.DatabaseError: foreign key constraint "glass_fill_manufacturer_glass_fill_id_fkey" cannot be implemented
DETAIL: Key columns "glass_fill_id" and "id" are of incompatible types: integer and character varying.
Any Ideas?
Note: The glass_fill_manufacturer Table hasn't been created yet django trys to on syncdb but fails. also the,
ALTER TABLE glass_fill ALTER COLUMN id TYPE INTEGER USING CAST(id AS INT);
line didn't alter the column as I thought.
glass_fill table schema:
-- Table: glass_fill
-- DROP TABLE glass_fill;
CREATE TABLE glass_fill
(
id character varying(36) NOT NULL,
name character varying(255),
temperature real,
density real,
viscosity real,
conductivity real,
heat_capacity real,
colour text,
CONSTRAINT glass_fill_pkey PRIMARY KEY (id )
)
WITH (
OIDS=FALSE
);
First, specify the name of the table to which the column you want to change belongs in the ALTER TABLE clause. Second, give the name of column whose data type will be changed in the ALTER COLUMN clause. Third, provide the new data type for the column after the TYPE keyword.
You can create a column having both keys (primary and foreign) but then it will be one to one mapping and add uniqueness to this column.
Changing a Column's Default Value. To set a new default for a column, use a command like: ALTER TABLE products ALTER COLUMN price SET DEFAULT 7.77; Note that this doesn't affect any existing rows in the table, it just changes the default for future INSERT commands.
ALTER TABLE glass_fill_manufacturer
ALTER COLUMN glass_fill_id TYPE INTEGER USING CAST(glass_fill_id AS INT)
;
I guess by your text that Django will somehow do it but if it doesn't:
ALTER TABLE glass_fill_manufacturer
drop constraint glass_fill_manufacturer_glass_fill_id_fkey
;
alter table glass_fill_manufacturer
ADD constraint glass_fill_manufacturer_glass_fill_id_fkey
foreign key (glass_fill_id) references glass_fill (id)
;
You should do the following:
glass_fill
, returning the values into the temporary tableIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With