'How to remove duplicates from the database table, alter the model with unique=True and makemigrations?

class CommonInfo(models.Model):
    name = models.CharField(max_length = 100)
    age = models.PositiveIntegerField()
    class Meta:
        abstract=True
        ordering=['name']
class Student(CommonInfo):
    home_group =models.CharField(max_length=5)
    class Meta(CommonInfo.Meta):
        db_table='student_info'

I have a similar database model with existing data. I want to add a uique=True on the field name. Is there any way I could remove the existing duplicate data before I alter the field name as unique?



Solution 1:[1]

First check whether other field depend on the row and then you can -- During development, open the database, go to the table find the row and delete.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ranu Vijay