{"action":"closed","issue":{"url":"https://api.github.com/repos/graphql-python/graphene-django/issues/459","repository_url":"https://api.github.com/repos/graphql-python/graphene-django","labels_url":"https://api.github.com/repos/graphql-python/graphene-django/issues/459/labels{/name}","comments_url":"https://api.github.com/repos/graphql-python/graphene-django/issues/459/comments","events_url":"https://api.github.com/repos/graphql-python/graphene-django/issues/459/events","html_url":"https://github.com/graphql-python/graphene-django/issues/459","id":334971816,"node_id":"MDU6SXNzdWUzMzQ5NzE4MTY=","number":459,"title":"ForeignKey causes Django error \"Models aren't loaded yet\"","user":{"login":"lucasmyers","id":22213594,"node_id":"MDQ6VXNlcjIyMjEzNTk0","avatar_url":"https://avatars0.githubusercontent.com/u/22213594?v=4","gravatar_id":"","url":"https://api.github.com/users/lucasmyers","html_url":"https://github.com/lucasmyers","followers_url":"https://api.github.com/users/lucasmyers/followers","following_url":"https://api.github.com/users/lucasmyers/following{/other_user}","gists_url":"https://api.github.com/users/lucasmyers/gists{/gist_id}","starred_url":"https://api.github.com/users/lucasmyers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucasmyers/subscriptions","organizations_url":"https://api.github.com/users/lucasmyers/orgs","repos_url":"https://api.github.com/users/lucasmyers/repos","events_url":"https://api.github.com/users/lucasmyers/events{/privacy}","received_events_url":"https://api.github.com/users/lucasmyers/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-06-22T18:12:34Z","updated_at":"2018-06-28T18:55:57Z","closed_at":"2018-06-28T18:55:57Z","author_association":"NONE","body":"I'm using a standard Django setup with graphene (using the standard `db.sqlite3` for now), but as soon as I add a ForeignKey field to one of my models and try `python manage.py makemigrations`, Django throws an error. I know this is not a Django issue because when I removed `graphene_django` from my installed apps (and removed `graphql` from `urls.py`), I was able to migrate and serve the app with no errors. Any help is greatly appreciated!\r\n\r\nVersions:\r\nPython v3.5.2\r\nDjango v2.0.5\r\ngraphene v2.1.2\r\ngraphene-django v2.0.0\r\n\r\nMy models.py file:\r\n```from django.db import models\r\nfrom django.conf import settings\r\nfrom graphene_django.types import DjangoObjectType\r\nimport uuid\r\n\r\n\r\nclass MLProject(models.Model):\r\n    title = models.TextField()\r\n    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)\r\n    tenant = models.CharField(max_length=500)\r\n    owner = models.CharField(max_length=500)\r\n    created_date = models.DateTimeField(auto_now_add=True)\r\n    status = models.CharField(max_length=50, blank=True, null=True)\r\n\r\n    def __str__(self):\r\n        return self.title\r\n\r\n\r\ndef pickle_file_path(instance, filename):\r\n    return settings.PICKLE_ROOT + ('{0}/{1}/'.format(instance.project.tenant, instance.project.owner)) + filename\r\n\r\n\r\nclass MLModel(models.Model):\r\n    name = models.TextField()\r\n    algorithm = models.TextField()\r\n    created_date = models.DateTimeField(auto_now_add=True)\r\n    status = models.CharField(max_length=50, blank=True, null=True)\r\n    pickle = models.FileField(upload_to=pickle_file_path, null=True, blank=True)\r\n    project = models.ForeignKey(MLProject, on_delete=models.CASCADE)\r\n    # the above line is what causes the error; if commented, the app migrates and serves just fine\r\n\r\n    def __str__(self):\r\n        return self.name\r\n\r\n\r\nclass MLProjectType(DjangoObjectType):\r\n    class Meta:\r\n        model = MLProject\r\n\r\n\r\nclass MLModelType(DjangoObjectType):\r\n    class Meta:\r\n        model = MLModel\r\n\r\n```\r\n\r\nError output:\r\n```Traceback (most recent call last):\r\n  File \"manage.py\", line 15, in <module>\r\n    execute_from_command_line(sys.argv)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/core/management/__init__.py\", line 371, in execute_from_command_line\r\n    utility.execute()\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/core/management/__init__.py\", line 347, in execute\r\n    django.setup()\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/__init__.py\", line 24, in setup\r\n    apps.populate(settings.INSTALLED_APPS)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/apps/registry.py\", line 112, in populate\r\n    app_config.import_models()\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/apps/config.py\", line 198, in import_models\r\n    self.models_module = import_module(models_module_name)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/importlib/__init__.py\", line 126, in import_module\r\n    return _bootstrap._gcd_import(name[level:], package, level)\r\n  File \"<frozen importlib._bootstrap>\", line 986, in _gcd_import\r\n  File \"<frozen importlib._bootstrap>\", line 969, in _find_and_load\r\n  File \"<frozen importlib._bootstrap>\", line 958, in _find_and_load_unlocked\r\n  File \"<frozen importlib._bootstrap>\", line 673, in _load_unlocked\r\n  File \"<frozen importlib._bootstrap_external>\", line 665, in exec_module\r\n  File \"<frozen importlib._bootstrap>\", line 222, in _call_with_frames_removed\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/mysite/myapp/models.py\", line 46, in <module>\r\n    class MLModelType(DjangoObjectType):\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/graphene/pyutils/init_subclass.py\", line 17, in __init__\r\n    super_class.__init_subclass__.__func__(cls, **kwargs)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/graphene/utils/subclass_with_meta.py\", line 48, in __init_subclass__\r\n    super_class.__init_subclass_with_meta__(**options)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/graphene_django/types.py\", line 65, in __init_subclass_with_meta__\r\n    construct_fields(model, registry, only_fields, exclude_fields),\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/graphene_django/types.py\", line 30, in construct_fields\r\n    converted = convert_django_field_with_choices(field, registry)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/graphene_django/converter.py\", line 59, in convert_django_field_with_choices\r\n    return convert_django_field(field, registry)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/functools.py\", line 743, in wrapper\r\n    return dispatch(args[0].__class__)(*args, **kw)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/graphene_django/converter.py\", line 173, in convert_field_to_djangomodel\r\n    model = field.related_model\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/utils/functional.py\", line 36, in __get__\r\n    res = instance.__dict__[self.name] = self.func(instance)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/db/models/fields/related.py\", line 94, in related_model\r\n    apps.check_models_ready()\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/apps/registry.py\", line 132, in check_models_ready\r\n    raise AppRegistryNotReady(\"Models aren't loaded yet.\")\r\ndjango.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.\r\n(env) lucasmyers@Evel-Knievel ~/Documents/bigsense/graphql_test/mysite $ python manage.py makemigrations\r\nTraceback (most recent call last):\r\n  File \"manage.py\", line 15, in <module>\r\n    execute_from_command_line(sys.argv)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/core/management/__init__.py\", line 371, in execute_from_command_line\r\n    utility.execute()\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/core/management/__init__.py\", line 347, in execute\r\n    django.setup()\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/__init__.py\", line 24, in setup\r\n    apps.populate(settings.INSTALLED_APPS)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/apps/registry.py\", line 112, in populate\r\n    app_config.import_models()\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/apps/config.py\", line 198, in import_models\r\n    self.models_module = import_module(models_module_name)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/importlib/__init__.py\", line 126, in import_module\r\n    return _bootstrap._gcd_import(name[level:], package, level)\r\n  File \"<frozen importlib._bootstrap>\", line 986, in _gcd_import\r\n  File \"<frozen importlib._bootstrap>\", line 969, in _find_and_load\r\n  File \"<frozen importlib._bootstrap>\", line 958, in _find_and_load_unlocked\r\n  File \"<frozen importlib._bootstrap>\", line 673, in _load_unlocked\r\n  File \"<frozen importlib._bootstrap_external>\", line 665, in exec_module\r\n  File \"<frozen importlib._bootstrap>\", line 222, in _call_with_frames_removed\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/mysite/myapp/models.py\", line 40, in <module>\r\n    class MLModelType(DjangoObjectType):\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/graphene/pyutils/init_subclass.py\", line 17, in __init__\r\n    super_class.__init_subclass__.__func__(cls, **kwargs)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/graphene/utils/subclass_with_meta.py\", line 48, in __init_subclass__\r\n    super_class.__init_subclass_with_meta__(**options)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/graphene_django/types.py\", line 65, in __init_subclass_with_meta__\r\n    construct_fields(model, registry, only_fields, exclude_fields),\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/graphene_django/types.py\", line 30, in construct_fields\r\n    converted = convert_django_field_with_choices(field, registry)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/graphene_django/converter.py\", line 59, in convert_django_field_with_choices\r\n    return convert_django_field(field, registry)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/functools.py\", line 743, in wrapper\r\n    return dispatch(args[0].__class__)(*args, **kw)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/graphene_django/converter.py\", line 173, in convert_field_to_djangomodel\r\n    model = field.related_model\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/utils/functional.py\", line 36, in __get__\r\n    res = instance.__dict__[self.name] = self.func(instance)\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/db/models/fields/related.py\", line 94, in related_model\r\n    apps.check_models_ready()\r\n  File \"/Users/lucasmyers/Documents/bigsense/graphql_test/env/lib/python3.5/site-packages/django/apps/registry.py\", line 132, in check_models_ready\r\n    raise AppRegistryNotReady(\"Models aren't loaded yet.\")\r\ndjango.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.\r\n```"}}
{"actor":{"display_login":"lucasmyers"}}