python - django - unique_together change - any danger in prod db? -
i have model:
class mymodel(models.model): name = models.charfield(max_length=10) nickname = models.charfield(max_length=10) title = models.charfield(max_length=10) score = models.charfield(max_length=10) class meta: unique_together = ['name', 'nickname']
what impact of changing unique_together
unique_together = ['name', 'title']
should careful before deploying update? there more 150.000 users online @ same time, happen in worst case?
yes, careful deploying change affects database. the documentation:
this tuple of tuples must unique when considered together. it’s used in django admin , enforced @ database level (i.e., appropriate unique statements included in create table statement).
so need migrate database change unique
constraint.
python manage.py makemigrations myapp python manage.py migrate myapp
you need check there aren't existing instances of model sharing pairing of unique constraints. check like:
mymodel.objects.filter(name__exact=models.f(title)).exists()
and amend or delete them.
you need ensure every model instance has title
, isn't empty string (even though shouldn't have happened).
mymodel.objects.filter(title__exact="")
Comments
Post a Comment