Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing a Django migration that depends on custom field from an old module

I have a Django 1.8 application whose initial migration relies on django-interval-field like this:

import interval.fields

migrations.CreateModel(
    name='Item',
    fields=[
        ...
        ('estimated_time', interval.fields.IntervalField(null=True, blank=True)),

I've since migrated this field to use Django's built-in DurationField, and I'm not using this module anymore, but I need to keep it in requirements.txt in order for my migrations to run.

However, this module throws errors when trying to upgrade to Django 1.9. In addition, I can't keep this module around forever. It would be nice to get rid of it.

I've tried squashing the migrations, but the squashed migration still contains the import interval.fields statement, and creates the interval field. All squashing does is concatenate everything into one file.

Can someone tell me how to go forward towards removing this module?

The Django app in question is here.

like image 678
nnyby Avatar asked Jan 30 '16 01:01

nnyby


People also ask

How do I delete old migration in Django?

To unapply migrations you should do the following: Use the python manage.py migrate your_app_name XXXX in case you want to unapply migrations after the XXXX migration. Otherwise use python manage.py migrate your_app_name zero to completely unapply all migrations.

Can you delete Django migrations?

Django will remove any prior migrations that were applied to the specified app (myApp). It searches for Python files (migration files) in the migrations folder of each project app, with the exception of init.py, and deletes them.


1 Answers

So, your squashing is not true squashing

  1. Remove this package from requirements.txt
  2. Remove import interval.fields from your models.py
  3. Modify your interval.fields.IntervalField(xxx) to some type available in Django in the related my_app_label/migrations/1234_some_migrations.py
  4. Done
like image 173
micfan Avatar answered Oct 16 '22 10:10

micfan