Opened 10 years ago
Last modified 10 years ago
#26023 closed Bug
Importing GenericForeignKey on Django 1.9 — at Version 2
| Reported by: | Chris Mitchell | Owned by: | nobody |
|---|---|---|---|
| Component: | contrib.contenttypes | Version: | 1.9 |
| Severity: | Normal | Keywords: | generic foreign keys |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
It appears it is not possible to import GenericForeignKey from outside a live Django project in 1.9. To reproduce this error:
from django.conf import settings settings.configure() from django.contrib.contenttypes.fields import GenericForeignKey
Produces:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/chris/.virtualenvs/wooey/local/lib/python2.7/site-packages/django/contrib/contenttypes/fields.py", line 5, in <module>
from django.contrib.contenttypes.models import ContentType
File "/home/chris/.virtualenvs/wooey/local/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 159, in <module>
class ContentType(models.Model):
File "/home/chris/.virtualenvs/wooey/local/lib/python2.7/site-packages/django/db/models/base.py", line 94, in __new__
app_config = apps.get_containing_app_config(module)
File "/home/chris/.virtualenvs/wooey/local/lib/python2.7/site-packages/django/apps/registry.py", line 239, in get_containing_app_config
self.check_apps_ready()
File "/home/chris/.virtualenvs/wooey/local/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
This seems to be occurring because ModelBase is attempting to get the app config, but the configuration step has not occurred.
Change History (2)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
| Description: | modified (diff) |
|---|
Note:
See TracTickets
for help on using tickets.
Could you clarify the use case? You need to have
django.contrib.contentypesinINSTALLED_APPS, I believe.