Cookiecutter-django: Error while making migrations

Created on 8 Aug 2018  路  12Comments  路  Source: pydanny/cookiecutter-django

位 python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 30, in
execute_from_command_line(sys.argv)
File "C:Users\Examto.virtualenvs\mzuegov-v4AlrsDA\lib\site-packages\django\core\management__init__.py", line 371, in execute_from_command_line
utility.execute()
File "C:Users\Examto.virtualenvs\mzuegov-v4AlrsDA\lib\site-packages\django\core\management__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:Users\Examto.virtualenvs\mzuegov-v4AlrsDA\lib\site-packages\django\core\management__init__.py", line 216, in fetch_command
klass = load_command_class(app_name, subcommand)
File "C:Users\Examto.virtualenvs\mzuegov-v4AlrsDA\lib\site-packages\django\core\management__init__.py", line 36, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "C:Users\Examto.virtualenvs\mzuegov-v4AlrsDA\lib\importlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in _load_unlocked
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "C:Users\Examto.virtualenvs\mzuegov-v4AlrsDA\lib\site-packages\django\core\management\commands\migrate.py", line 12, in
from django.db.migrations.autodetector import MigrationAutodetector
File "C:Users\Examto.virtualenvs\mzuegov-v4AlrsDA\lib\site-packages\django\db\migrations\autodetector.py", line 11, in
from django.db.migrations.questioner import MigrationQuestioner
File "C:Users\Examto.virtualenvs\mzuegov-v4AlrsDA\lib\site-packages\django\db\migrations\questioner.py", line 9, in
from .loader import MigrationLoader
File "C:Users\Examto.virtualenvs\mzuegov-v4AlrsDA\lib\site-packages\django\db\migrations\loader.py", line 8, in
from django.db.migrations.recorder import MigrationRecorder
File "C:Users\Examto.virtualenvs\mzuegov-v4AlrsDA\lib\site-packages\django\db\migrations\recorder.py", line 9, in
class MigrationRecorder:
File "C:Users\Examto.virtualenvs\mzuegov-v4AlrsDA\lib\site-packages\django\db\migrations\recorder.py", line 22, in MigrationRecorder
class Migration(models.Model):
File "C:Users\Examto.virtualenvs\mzuegov-v4AlrsDA\lib\site-packages\django\db\models\base.py", line 100, in __new__
app_config = apps.get_containing_app_config(module)
File "C:Users\Examto.virtualenvs\mzuegov-v4AlrsDA\lib\site-packages\djangoapps\registry.py", line 244, in get_containing_app_config
self.check_apps_ready()
File "C:Users\Examto.virtualenvs\mzuegov-v4AlrsDA\lib\site-packages\djangoapps\registry.py", line 127, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

Most helpful comment

Turns out it's because the CELERY_BROKER_URL environment variable is not set at this line:

https://github.com/pydanny/cookiecutter-django/blob/07060eaecc07c444470b91b0915b63b6f4fc88f7/%7B%7Bcookiecutter.project_slug%7D%7D/config/settings/base.py#L236

You can replace it with something along the lines of the following:

CELERY_BROKER_URL = env('CELERY_BROKER_URL', default="redis://localhost:6379")

All 12 comments

I'm sorry, but this is impossible for us to address/respond, please follow one of the "new issue" templates provided and fill in the details.

This project is run by volunteers in their free time, and simply copy/pasting a stacktrace without explanations is disrespectful of our time.

This seems to occur on a fresh project simply trying to call makemigrations

These settings might help in recreating this:

windows [n]:
use_pycharm [n]:
use_docker [n]: y
Select postgresql_version:
1 - 10.4
2 - 10.3
3 - 10.2
4 - 10.1
5 - 9.6
6 - 9.5
7 - 9.4
8 - 9.3
Choose from 1, 2, 3, 4, 5, 6, 7, 8 [1]: 1
Select js_task_runner:
1 - None
2 - Gulp
Choose from 1, 2 [1]: 1
custom_bootstrap_compilation [n]:
use_compressor [n]:
use_celery [n]: y
use_mailhog [n]: y
use_sentry [n]: y
use_whitenoise [n]: y
use_heroku [n]: n
use_travisci [n]:
keep_local_envs_in_vcs [y]:
debug [n]:

I've tried to use the same options as you provided and I cannot reproduce. After generating the project, I ran:

$ docker-compose -f local.yml up
[...] # Build images & start each service
$ docker-compose -f local.yml run django python manage.py makemigrations
Starting debug_migrations_issue_postgres_1 ... done
Starting debug_migrations_issue_mailhog_1  ... done
PostgreSQL is available
No changes detected

Are you able to share a sample project with the issue?

same here, after generating the project i've tried set up just in local, with > python manage.py migrate, not inside docker

@rchdlps is your project using Docker at all?

Not this time, i've tried the both way, using docker everything is going ok, but if i put option without docker, and try migrate this issue occur

windows [n]: n
use_pycharm [n]: n
use_docker [n]: n
Select postgresql_version:
1 - 10.4
2 - 10.3
3 - 10.2
4 - 10.1
5 - 9.6
6 - 9.5
7 - 9.4
8 - 9.3
Choose from 1, 2, 3, 4, 5, 6, 7, 8 [1]: 1
Select js_task_runner:
1 - None
2 - Gulp
Choose from 1, 2 [1]: 1
custom_bootstrap_compilation [n]: n
use_compressor [n]: n
use_celery [n]: y
use_mailhog [n]: y
use_sentry [n]: y
use_whitenoise [n]: y
use_heroku [n]: n
use_travisci [n]: n
keep_local_envs_in_vcs [y]: y
debug [n]: y

this issue go out if i put Celery off my project, i don't know if make some sense

I can reproduce the issue with your answers, so there is probably something wrong in the settings for the combination that you selected.

To find the root cause, you can try to look at where use_celery without Docker is not generating some bits from the config.

I'll try to have a look later when I can.

Turns out it's because the CELERY_BROKER_URL environment variable is not set at this line:

https://github.com/pydanny/cookiecutter-django/blob/07060eaecc07c444470b91b0915b63b6f4fc88f7/%7B%7Bcookiecutter.project_slug%7D%7D/config/settings/base.py#L236

You can replace it with something along the lines of the following:

CELERY_BROKER_URL = env('CELERY_BROKER_URL', default="redis://localhost:6379")

That's right!! It worked for me o/ thank you

Same problem here with these parameters:

windows [n]:
use_pycharm [n]:
use_docker [n]: y
Select postgresql_version:
1 - 10.5
2 - 10.4
3 - 10.3
4 - 10.2
5 - 10.1
6 - 9.6
7 - 9.5
8 - 9.4
9 - 9.3
Choose from 1, 2, 3, 4, 5, 6, 7, 8, 9 (1, 2, 3, 4, 5, 6, 7, 8, 9) [1]: 7
Select js_task_runner:
1 - None
2 - Gulp
Choose from 1, 2 (1, 2) [1]:
custom_bootstrap_compilation [n]:
use_compressor [n]:
use_celery [n]:
use_mailhog [n]:
use_sentry [n]:
use_whitenoise [n]:
use_heroku [n]:
use_travisci [n]:
keep_local_envs_in_vcs [y]:
debug [n]:

On Linux Mint 18.3 with Python 3.6.8 installed in a virtualenv. PIP 19.0.1. Cookiecutter 1.6.0. Migrations ran outside Docker container.

(No celery involved, as you can see, so... I do not what to think of #1748).

FYI: cookiecutter-django seems to work fine on my machine with "use_docker [n]: n".

Was this page helpful?
0 / 5 - 0 ratings