Import Error while upgrading the Django v1.11 to v2.0

I have met a weird issue while upgrading the Django v1.11 to v2.0, python 2 to 3. I can’t import the model class in one module to another module model file. It had never happened before. Does anyone know why and how to resolve it?
ImportError: cannot import name

There are a couple different reasons why this error can occur. Please provide more details. Show the line causing the error along with the name of the file it appears in.
(This is likely just the starting point, we may need to ask for a lot more to find the root issue.)

Did Django change the way to load an app in v2.0?
In v1.11 I only added the app name into INSTALLED_APPS like this


Do I need to create the file and OfferConfig class to like this


Here is traceback:

Traceback (most recent call last):
  File "src/slots/", line 20, in <module>
  File "/opt/kff/Whiplash-Server-Env/lib/python3.6/site-packages/django/core/management/", line 371, in execute_from_command_line
  File "/opt/kff/Whiplash-Server-Env/lib/python3.6/site-packages/django/core/management/", line 347, in execute
  File "/opt/kff/Whiplash-Server-Env/lib/python3.6/site-packages/django/", line 24, in setup
  File "/opt/kff/Whiplash-Server-Env/lib/python3.6/site-packages/django/apps/", line 112, in populate
  File "/opt/kff/Whiplash-Server-Env/lib/python3.6/site-packages/django/apps/", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/root/.pyenv/versions/3.6.15/lib/python3.6/importlib/", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/opt/kff/Whiplash-Server/src/slots/wp_faction_mission/", line 7, in <module>
    from wp_blueprints.core.mixins import ExpiryDateMixin
  File "/opt/kff/Whiplash-Server/src/slots/wp_blueprints/core/", line 3, in <module>
    from wp_blueprints.models import ModelExpiry
  File "/opt/kff/Whiplash-Server/src/slots/wp_blueprints/", line 5, in <module>
    from wp_brick.models import BrickSettings
  File "/opt/kff/Whiplash-Server/src/slots/wp_brick/", line 724, in <module>
    class Deeplink_shop(models.Model):
  File "/opt/kff/Whiplash-Server/src/slots/wp_brick/", line 728, in Deeplink_shop
    from wp_battleshop.models import BattleShop
  File "/opt/kff/Whiplash-Server/src/slots/wp_battleshop/", line 4, in <module>
    from wp_inventory.models import Currency
  File "/opt/kff/Whiplash-Server/src/slots/wp_inventory/", line 11, in <module>
    from wp_grabbag.models import GrabBag
  File "/opt/kff/Whiplash-Server/src/slots/wp_grabbag/", line 8, in <module>
    from wp_blueprints.core.mixins import ExpiryDateMixin
ImportError: cannot import name 'ExpiryDateMixin'

You have a circular import situation. You have a case where module “A” imports module “B”, which then imports module “C” which then tries to import module “A”.

Look at all the import statements above, you’ll see the following line twice:

And to address your other question about app definitions, both are valid. The AppConfig is necessary if there’s something you need to do that is handled by the AppConfig class. Otherwise both work exactly the same.

1 Like