问题
My task model:
class Tasks(models.Model):
state = models.CharField(max_length = 150)
I want to change the state field to ForeignKey like state = models.ForeignKey(States)
Where States model would be:
class States(model.Model):
name = models.CharField(max_length = 150)
BTW I am using Django non-rel with django mongodb.
Is it easy to do using south?or is thr any other way to do it?
回答1:
I will do it in six steps (migrations):
- First step a data_migration (south command): I create the States objects.
- Second step a schema_migration (south command): I add a fk in Tasks the name will be state_bk
- Third step a data_migration: Migrate all tasks and assigned the states to the tasks
- Quarter schema_migration: Delete the states charfield and create states fk
- Fifth data_migration: Migrate the values from state_bk to state
- Sixth schema_migration: Delete state_bk field
This is easy, but a little tedious
来源:https://stackoverflow.com/questions/10462864/how-can-i-replace-a-charfield-to-foreignkey-using-south-in-django