Django reset migration and avoid default value in makemigration


It’s common when we need to add new key and migration said we need to defined default values for the field (eg: using datetime). Well, there another trick we can use.

1. Remove all tables in apps
Yes, we create migration to remove all tables in apps. To do this, first go to APPS in settings.py. Put comments on all apps below your app which you want to reset. Let’s say, we have app “credit”. We need to modify models and assign into some foreignkey (null not allowed here).

Comment another app below credits.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
INSTALLED_APPS = (
    ‘grappelli’,
    ‘django.contrib.admin’,
    ‘django.contrib.auth’,
    ‘django.contrib.contenttypes’,
    ‘django.contrib.sessions’,
    ‘django.contrib.messages’,
    ‘django.contrib.staticfiles’,
    ‘accounts’,
    ‘friends’,
    ‘credits’,
    #’memberships’,
    #’rewards’,
)

Then, make sure to comment admins.py under “credits”.

2. Generate migration to delete model credits.
Go to credits apps and edit models.py. We just comment all line inside models.py then do makemigration after.

1
2
3
4
5
Migrations for ‘credits’:
  0003_auto_20140926_1454.py:
    – Remove field a from credit
    – Remove field b from credit
    – Delete model Credit

When we run this migration, our tables will deleted.

3. Add your foreginkey or whatever things you need and makemigrations.

4. Done 🙂


One response to “Django reset migration and avoid default value in makemigration”

  1. Hi, im having the same issue i didnt understand the “Then, make sure to comment admins.py under “credits” ” part can you helo me please

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.