Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove a Django migration file?

I made a migration, and realised that I made an error (by adding a default value), I then made a new migration which allows for null.

I don't want my colleagues to run the first migration which adds a default value to thousands of records. How can I delete that migration without breaking the current migrations (usually if you just delete a migration you get a heap of errors which are a pain to fix).

I'd assume you could use a command? I'd assume it'd be something like this ~>

e.g django manage.py deletemigration <migration_id>

like image 686
James111 Avatar asked Mar 12 '23 11:03

James111


1 Answers

Squash

You can do a ./manage.py squashmigrations since one of your migrations are effectively cancelling out another the end result will be the field being nullable. Your colleagues will not have to go through the step of adding a default value.

Squashing is the act of reducing an existing set of many migrations down to one (or sometimes a few) migrations which still represent the same changes.

Edit the migration file

You can edit the migration file by hand to remove the changes to the column. A migration can actually have an empty migration

class Migration(migrations.Migration):

    dependencies = [
        (some stuff here),
    ]

    operations = []
like image 91
e4c5 Avatar answered Apr 03 '23 02:04

e4c5