django south migration, doesnt set default

前端 未结 3 1367
野的像风
野的像风 2021-02-08 10:57

I use south to migrate my django models. There is however a nasty bug in south. It doesn\'t set default values in Postgres Databases. Example:

created_at = model         


        
3条回答
  •  一生所求
    2021-02-08 11:23

    If you are auto-generating your migrations using:

    ./manage.py schemamigration app_name --auto
    

    Then you need to make a small edit to the migration before you actually apply it. Go into the generated migration (should be called something like app_name/migrations/000X__auto_add_field_foo.py) and look for the argument:

    keep_default=False
    

    in the db.add_column call. Simply change this to:

    keep_default=True
    

    And Django will now apply your default value to the actual schema, in addition to any existing rows. Would be great if South had some kind of setting to generate this parameter as True by default, but no such luck. You will need to make this edit every time.

提交回复
热议问题