2013年1月26日 星期六

Reverse Migration


South Migration


在 Django 上使用 South 做資料庫的 migration 很方便。
但有的時候你會做出些無法回復的migrate, 你會看到令人害怕的訊息:



    user = models.ForeignKey(User)


    user = models.ForeignKey(User, null=True, default=None)


 ? The field 'SuggestedBrand.user' does not have a default specified, yet is NOT NULL.
 ? Since you are making this field nullable, you MUST specify a default
 ? value to use for existing rows. Would you like to:
 ?  1. Quit now, and add a default to the field in models.py
 ?  2. Specify a one-off value to use for existing columns now
 ?  3. Disable the backwards migration by raising an exception.

這時,你會覺得早就指定好了 default, 但是south 多考慮了 reverse migration, 所以,簡單一點來說,選3 是沒關係的。

Reference



    http://south.aeracode.org/ticket/917