Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revert migration on deleted not null field

I've got a model with a non-null field which I deleted:

class Spam(models.Model):
    slug = models.SlugField(allow_unicode=True)  # deleted

After I made the migrations and applied them, I wanted to revert them. But obviously, this results in

django.db.utils.IntegrityError: NOT NULL constraint failed: eggs_spam.slug

How can I revert the migration?

like image 202
Joren Avatar asked Aug 15 '17 13:08

Joren


1 Answers

There is an easier way:

  1. Find migration where you have initially add slug field
  2. Add default value to slug field
  3. Unapply last migration
  4. Remove default value from initial slug field migration
like image 130
ar7n Avatar answered Oct 03 '22 15:10

ar7n