0

So, I'm using Zappa on AWS Lambda. I just added a custom user model to my project and tried to migrate to the RDS on AWS and Zappa gives me the following error:

InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency accounts.0001_initial on database 'default'.

Now, I know that if I got this error on my local server, I would do this:

python manage.py migrate admin zero
python manage.py migrate auth zero
python manage.py migrate contenttypes zero
python manage.py migrate sessions zero

I would then run the migrations to destroy their tables and recreate them again (see this helpful SO post)

However, if I ran

zappa manage dev migrate 

after that, I get

InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency accounts.0001_initial on database

How should I do the same thing on the AWS RDS using Zappa or should I do something else?

EarlyCoder
  • 1,213
  • 2
  • 18
  • 42
  • 1
    if you're going to destroy and rebuild your tables, why not destroy and rebuild your migration files? – Daniel Jun 07 '21 at 22:54

1 Answers1

0

I simple destroyed the table using the zappa-django-utils command:

zappa manage prod drop_pg_db
zappa manage prod create_pg_db

The tricky part was to create a new admin user. Since I replaced the auth model with the accounts model, I had to use the raw python command:

zappa invoke --raw dev "from django.accounts.models import User; User.objects.create_superuser('admin@yourdomain.com', 'ohsosecretepass')"

Typically, the custom user model should be implemented before any migrations as many things are related to the User model. So, dropping all the tables were inevitable though I tried to avoid it.

EarlyCoder
  • 1,213
  • 2
  • 18
  • 42