Unique_together change - any danger in prod db?

I have a 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 is the impact of change unique_togetheron

unique_together = ['name', 'title']

Should I be careful before deploying this update? There are currently more than 150,000 users online, what could happen in the worst case?

+4
source share
1 answer

Yes, I will carefully deploy this change as it affects the database. From the documentation :

This is a tuple of tuples, which should be unique when viewed together. It is used by the Django administrator and applied at the database level (that is, the corresponding UNIQUE statements are included in the CREATE TABLE statement).

, UNIQUE.

python manage.py makemigrations myapp
python manage.py migrate myapp

, - , . - :

MyModel.objects.filter(name__exact=models.F(title)).exists()

.

, title ( , , ).

MyModel.objects.filter(title__exact="")
+4

Source: https://habr.com/ru/post/1584038/


All Articles