2015-06-03 73 views
1

由於某些原因,Django要求我隨機遷移,當此字段未更改時。遷移文件是相同的。Django CharField,選擇和遷移

型號:

PROGRESS_CHOICE = { 
     ('1', '1.start'), 
     ('2', '2.driver_arrived_pick_up'), 
     ('3', '3.hope_in'), 
     ('4', '4.driver_arrived_destination'), 
     ('5', '5.end') 
    } 

    progress = models.CharField(max_length=20, choices=PROGRESS_CHOICE, default=1, blank=True) 

遷移:1.

class Migration(migrations.Migration): 
    dependencies = [ 
     ('api', '0031_auto_20150603_1515'), 
    ] 

    operations = [ 
     migrations.AlterField(
      model_name='ride', 
      name='progress', 
      field=models.CharField(max_length=20, default=1, blank=True, choices=[('1', '1.start'), ('3', '3.hope_in'), ('4', '4.driver_arrived_destination'), ('2', '2.driver_arrived_pick_up'), ('5', '5.end')]), 
      preserve_default=True, 
     ), 
    ] 

2.

class Migration(migrations.Migration): 
    dependencies = [ 
     ('api', '0032_auto_20150603_1734'), 
    ] 

    operations = [ 
     migrations.AlterField(
      model_name='ride', 
      name='progress', 
      field=models.CharField(default=1, max_length=20, choices=[('1', '1.start'), ('4', '4.driver_arrived_destination'), ('5', '5.end'), ('3', '3.hope_in'), ('2', '2.driver_arrived_pick_up')], blank=True), 
      preserve_default=True, 
     ), 
    ] 

回答

1

它發生是因爲PROGRESS_CHOICEdict,而它必須是list或更好的tuple

PROGRESS_CHOICES = (
    ('1', '1.start'), 
    ('2', '2.driver_arrived_pick_up'), 
    ('3', '3.hope_in'), 
    ('4', '4.driver_arrived_destination'), 
    ('5', '5.end'), 
) 

CharField的choices接受任何可迭代所以它的工作,但dict所以每次使遷移時間不維持秩序,同時被轉化爲列出它是隨機洗牌。

+0

我的感謝,沒有注意到它:) – jTiKey

1

您的默認類型不匹配您的選擇。嘗試改變爲默認='1'。