我目前被困在一個catch與我的Django應用程序22。當我從UUID移動到普通的舊ID時(由於它是物理常數,數據不會改變),我必須將列的類型從Varying char更改爲Integer。現在Django的一陣痙攣原本約不能夠從varchar轉換爲INT,所以我「幫助」它具有:如何更改PostgreSQL中的列類型和所有外鍵?
ALTER TABLE glass_fill ALTER COLUMN id TYPE INTEGER USING CAST(id AS INT);
現在,它說:
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.
什麼想法?
注意:glass_fill_manufacturer表尚未創建,但Django嘗試在syncdb上執行,但失敗。還有,
ALTER TABLE glass_fill ALTER COLUMN id TYPE INTEGER USING CAST(id AS INT);
線沒有改變列,因爲我認爲。
glass_fill表模式:
-- 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
);
請發佈'glass_fill_manufacturer'腳本。 – Quassnoi
沒有腳本,當我運行syncdb時,它由Django實時生成。 – Jharwood