Delete all migration files

137 views
Skip to first unread message

Noumia Ngangoum

unread,
May 12, 2016, 4:05:56 PM5/12/16
to Django users
Hi,
is there a way to delete all migrations history , i.e. from the database and also from the apps ?

Eugene Gavrish

unread,
May 12, 2016, 7:02:07 PM5/12/16
to Django users
Hi,
1) truncate django_migrations table
2) cleanup  migration  folders in your apps



Best regards,
Eugene

четверг, 12 мая 2016 г., 23:05:56 UTC+3 пользователь Noumia Ngangoum написал:

Noumia Ngangoum

unread,
May 12, 2016, 11:11:43 PM5/12/16
to Django users
Yeah Eugene, I know that, that's how I do now.
I was looking for a one-liner command or something.

Michal Petrucha

unread,
May 13, 2016, 1:43:20 AM5/13/16
to django...@googlegroups.com
On Thu, May 12, 2016 at 08:11:42PM -0700, Noumia Ngangoum wrote:
> Yeah Eugene, I know that, that's how I do now.
> I was looking for a one-liner command or something.

There is no one-liner, because you are not supposed to remove all
migrations. The entire point of migrations is that once you crate
them, you keep them together with your code.

Occasionally you might want to squash your migrations, in case the
migration history becomes too long and takes too much time to process
one-by-one, but even when you do that, you do not simply remove all
migrations and reset the migrations table.

Cheers,

Michal
signature.asc

Gergely Polonkai

unread,
May 13, 2016, 2:13:59 AM5/13/16
to Django users

Hello,

Michal is right, except…

If you have only one server running your code, there is no real need to keep your unsquashed migrations; do a squash, and remove everything else.

If, however, your app's source is public, imagine the following scenario:

You publish your app with 3 migration files. I install it and migrate. Then you create 2 more, but later decide to squash all 5 into one (resulting in a 0001_0005 migration file) and remove the old ones. Now I hear about the cool new feature you just built in and want to use it. I upgrade the app, run migrate… and Django will miss the 0004 and 0005 files.

If I create an empty migration with the same name of your 0004 (I can check it in the squashed migration file), then run makemigration, I'll get the same result as you (I have to rename 0005 again, of course). However, if you had a RunPython step in your 0004, I will know nothing about it, and may destroy my data (of course not, I have backups).

=====

I have some Django projects in production, and we always keep migration files. We also have most of them squashed just in case (it speeds up testing a lot).

I hope I helped :)

Best,
Gergely

> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20160513054234.GC435%40koniiiik.org.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages