L
L
Lopus2016-04-10 10:48:00
Django
Lopus, 2016-04-10 10:48:00

How to rollback makemigrations in django?

Added a field to the model:

slug = models.SlugField(u'url', max_length=255, blank=True, null=True, unique=True)

didn't specify a default value, ran makemigrations.
Django created the migrations, but when you call migrate, it throws this error:
django.db.utils.IntegrityError: (1062, "Duplicate entry '' for key 'slug'")

Those. django is trying to create a unique field with the same value.
How can this last makemigrations be rolled back? Or maybe do some kind of test before makemigrations so that there are no such accidents?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2016-04-10
@Lopus

Just delete this migration file if it hasn't already been applied. Correct and run makemigrations again.
Manage.py show migrations shows applied and unapplied migrations.
By specifying a number, you can rollback to a previous migration
manage.py migrate <model> <migration number>

L
Leonid, 2019-12-11
@stilet69

Unknown command: 'show'. Did you mean show_urls?
Why is there no such command?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question