Django : unique=True constraint does not get removed using django migrations

Viewed 231

I have a model as :

class order(models.Model):
    serial = models.CharField(max_length=20,unique=True)

I've migrated this model using django migrations (PostgreSql).

Now I wish to remove the unique constraint.

class order(models.Model):
    serial = models.CharField(max_length=20)

On running makemigrations, only an AlterField migration is created :

migrations.AlterField(
            model_name='order',
            name='serial',
            field=models.CharField(max_length=20),
        ),

On migrating this, the unique constraint is not removed. (it's visible in pgAdmin).

After this, I tried removing the constraint manually. The unique constraint name as in pgAdmin is 'order_serial_key'. In the migrations file, I added :

migrations.RemoveConstraint(
            model_name='order',
            name='order_serial_key'
        )

On migrating, it shows ValueError: No constraint named order_serial_key on model order

How can I remove this constraint using migrations ?

0 Answers
Related