django model is getting Alter Field alert on every migrations

Viewed 476

i am getting alter filed alert every time when i run the command python manage.py makemigrations i also delete my database old migration files but the alert is still there can anybody know how can i solve this issue?

Migrations for 'assignment':
  assignment/migrations/0012_auto_20201016_0754.py
    - Alter field city on assignment
    - Alter field status on assignment
class Assignment(models.Model):

    CITY_SELECT = {
        ('i', 'Islamabad'),
        ('l', 'Lahore'),
        ('m', 'Multan'),
        ('k', 'Karachi'),
        ('q', 'Queta'),
        ('p', 'Pashawar')
    }

    STATUS_SELECT = {
        ('p', 'Pendding'),
        ('d', 'Done'),
        ('i', 'In field'),
        ('c', 'Cancel')
    }

    place = models.CharField(max_length=100)
    desc = models.CharField(max_length=500)
    reporter = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
    created_on = models.DateTimeField(auto_now_add=True)
    assign_time = models.DateTimeField(auto_now=False, null=True)
    city = models.CharField(choices=CITY_SELECT, max_length=9)
    status = models.CharField(choices=STATUS_SELECT, max_length=8)
1 Answers

Likely the set is "shuffled" each time in a different order, making the choices unpredictable. If you run the Python process multiple times, each time the hashing constant is different. You can use a list, this will ensure the order is always the same:

class Assignment(models.Model):
    
    CITY_SELECT = [  # ← use a list
        ('i', 'Islamabad'),
        ('l', 'Lahore'),
        ('m', 'Multan'),
        ('k', 'Karachi'),
        ('q', 'Queta'),
        ('p', 'Pashawar')
    ]
    
    STATUS_SELECT = [  # ← use a list
        ('p', 'Pendding'),
        ('d', 'Done'),
        ('i', 'In field'),
        ('c', 'Cancel')
    ]

    place = models.CharField(max_length=100)
    desc = models.CharField(max_length=500)
    reporter = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
    created_on = models.DateTimeField(auto_now_add=True)
    assign_time = models.DateTimeField(auto_now=False, null=True)
    city = models.CharField(choices=CITY_SELECT, max_length=9)
    status = models.CharField(choices=STATUS_SELECT, max_length=8)
Related