9

I'm trying to run django migrations on a freshly installed Heroku instance but was getting a ProgrammingError. The error was due to some module-level queries that were being performed in a totally separate module and shouldn't be called at all during the migration.

It turns out that the reason they files were being called is because they were in a file that was imported into my urls.py and, for some reason, Django was loading those urls.

Is there some reason Django must load the urls even though migrations don't depend on them, and is there any way to prevent them from being loaded?

Soviut
  • 88,194
  • 49
  • 192
  • 260
  • It sounds likely there is an error somewhere you should iron out. But if it's just a problem with the migration you can go into the ```migrations``` folder and edit the fille that is causing the problem. – rurp Jul 14 '16 at 21:49
  • Can you post gists of your URL file as well as the problem file? – Yatharth Agarwal Jul 15 '16 at 03:15
  • 2
    I've just got through hours of being plagued with the same `ProgrammingError` issue during migrations (this is just in development tg), also because it's pulling in my `urls.py`. Did you find out why `manage.py` is doing this @Soviut? – toxefa Jan 15 '17 at 20:52

2 Answers2

6

There is a boolean class attribute in BaseCommand class called requires_system_checks, which is True by default. It will check all potential problems prior to executing the command. In the 3.0 version, there is a flag called --skip-checks which skips running system checks prior to running the command. I checked on a brand new generated Django project and it worked without raising the expected exception that I wrote intentionally in the urls.py module.

Davit Tovmasyan
  • 3,238
  • 2
  • 20
  • 36
1

I added the following lines on top, in models.py file.

from django.core.management.base import BaseCommand
BaseCommand.requires_system_checks = False
Sheikh Abdul Wahid
  • 2,623
  • 2
  • 25
  • 24