1

I'm trying to setup a Django project and am faced with the following error:

WARNINGS:
?: (rest_framework.W001) You have specified a default PAGE_SIZE pagination rest_framework setting,without specifying also a DEFAULT_PAGINATION_CLASS.
    HINT: The default for DEFAULT_PAGINATION_CLASS is None. In previous versions this was PageNumberPagination. If you wish to define PAGE_SIZE globally whilst defining pagination_class on a per-view basis you may silence this check.
Traceback (most recent call last):
  File "manage.py", line 18, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 82, in handle
    executor.loader.check_consistent_history(connection)
  File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/db/migrations/loader.py", line 291, in check_consistent_history
    connection.alias,
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration events.0001_initial is applied before its dependency commons.0001_initial on database 'default'.
make: *** [migrate] Error 1

I am running this from within a virtual environment, and have a docker-compose container for a postgres db running. Not sure how to start debugging this or why its happening. Any help would be appreciated

irmaz
  • 51
  • 2
  • 4
  • can you share what are the dependencies of both events.001_initial and commons.0001_initial ? it might just be a matter of editing one of them, so that you don't have to run separately migrations for events and for commons – Gers Dec 02 '19 at 06:11
  • @Gers Events has `dependencies = [ ("commons", "0001_initial"), migrations.swappable_dependency(settings.AUTH_USER_MODEL), ]` and commons has an empty array for dependencies. – irmaz Dec 02 '19 at 23:50
  • i'm not sure about it either, but you can try to add `migrations.swappable_dependency(settings.AUTH_USER_MODEL)` in commons initial migration file or have a look at the issue that @Md. Rakibul Islam mentionned https://stackoverflow.com/questions/49957057/django-migration-order-with-auth-user-model – Gers Dec 04 '19 at 06:43
  • related (if not duplicate) question: https://stackoverflow.com/q/37627464/4744341 – natka_m Jul 08 '20 at 12:50

2 Answers2

0

Follow these steps in your migrations folder inside the project:

Delete the pycache and the 0001_initial files.

Delete the db.sqlite3 from the root directory (be careful all your data will go away). on the terminal run:

python manage.py makemigrations
python manage.py migrate

Note: don't forget to take a backup of your data.

For more detail, you can follow the link

Rakibul Islam
  • 954
  • 1
  • 14
  • 25
0

As per your snapshot: you need to run command:- python manage.py migrate commons and then migrate for events model.

Lokesh
  • 496
  • 4
  • 11
  • This still results in the same error. For some reason events.0001_initial keeps getting applied before the commons one – irmaz Dec 05 '19 at 04:32
  • @irmaz first drop django_migrations table from your database the again run the commands. As this table holds information about which migration files you have already run in database. – Lokesh Dec 05 '19 at 06:41