在Postgres 9.1上使用Django 1.3。Django 1.3 - BooleanField到DateTimeField遷移失敗
我的任務是將兩個舊布爾字段pulled
和mail_report
遷移到時間戳。
在試圖遷移時,我得到以下錯誤,我不確定如何在數據庫中手動刪除非空約束以避免讓我將所有記錄強制轉換爲空。 django.db.utils.DatabaseError: column "pulled" cannot be cast to type timestamp with time zone
任何有助於解決這個問題的方法都不會讓我手動修補我們的實時數據庫,我們將不勝感激。
模型聲明的變化:
# Reporting Checked Flags
# pulled => Object has been processed through order_picklist
- pulled = models.BooleanField(default=False)
+ pulled = models.DateTimeField(blank=True, null=True, default=None)
# mail_report => Object has been processed through report_mailing_list
- mail_report = models.BooleanField(default=False)
+ mail_report = models.DateTimeField(blank=True, null=True, default=None)
我認爲最好在兩次分離的遷移中做到這一點:首先,從模型中刪除兩列,然後用新類型重新創建它們。 –
@PauloBu我想我唯一的麻煩是我需要保存現有布爾的狀態,所以我可以添加一個datetime.now()標記爲所有當前標記爲true的標記。 – DivinusVox