Upgrading from Django 1.6.7 to 1.8.3, RuntimeError: conflicting models in the application

I am using Django 1.8.3 and Python 2.7.6

My project structure:
project/
   __init__.py
   app/
      __init__.py
      sa1/
         __init__.py
         admin.py
         models.py
         interface.py
      sa2/
         __init__.py
         forms.py
         urls.py
         views.py
      app/
         __init__.py
         admin.py
         models.py
         tests.py
         views.py

      

I tried to import models in sa2 / forms.py file like this:

from project.app.sa2.models import Mo1, Mo2, Mo3

      

An error occured -

Exception Type: RuntimeError at /
    Exception Value: Conflicting 'mo1' models in application 'app': <class
 'project.app.models.Mo1'> and <class 'app.models.Mo1'>

      

I tried to solve this problem using: conflicting Django 1.7 models

So, I changed it to:

from app.sa2.models import Mo1, Mo2, Mo3

      

An error occurred => ImportError: no module named sa2

So I took a different approach by getting rid of __init__.py

in the project / as stated at https://code.djangoproject.com/ticket/22280

This caused another error => ImportError: No module named project.website.settings

Please help me debug this.

+3


source to share


1 answer


I had some kind of problem. Inside sa2 try

from sa2.models import Mo1, Mo2, Mo3 

      

or alternatively

from .models import Mo1, Mo2, Mo3

      



CATCH : Don't forget to use the same import files in your forms.py, tests.py files or wherever you import those models. If you only update one import, it won't work and you will still get the same error.

The problem arises from double imports. For more information see this: Double Import Trap

Good luck.

PS no __init__.py

were damaged in the process

+2


source







All Articles