Django - Change a ForeignKey relation to OneToOne

前端 未结 3 452
感动是毒
感动是毒 2021-02-07 07:44

I am using South with my Django app. I have two models that I am changing from having a ForeignKey relation to having a OneToOneField relation. When I

3条回答
  •  旧巷少年郎
    2021-02-07 08:17

    First thing I would try would be to add a db.delete_unique(...) in various places to see if I could hack it.

    Failing that, I'd split it up into 3 migrations:

    1. a schema migration to add a new column for the OneToOne
    2. a data migration to copy all FK values from old column over to new
    3. a schema migration to remove the old column, which then I'd edit manually to include a command to rename the new column to the same as the old one.

提交回复
热议问题