I'm 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 as follows:
from project.app.sa2.models import Mo1, Mo2, Mo3
This raised an error -
Exception Type: RuntimeError at /
Exception Value: Conflicting 'mo1' models in application 'app': <class
'project.app.models.Mo1'> and <class 'app.models.Mo1'>
I've tried to solve it using: Django 1.7 conflicting models
So, I Changed it to:
from app.sa2.models import Mo1, Mo2, Mo3
This raised an error => ImportError: no module named sa2
So, I took another approach by getting rid of __init__.py in project/ as mentioned in https://code.djangoproject.com/ticket/22280
This raised another error => ImportError: No module named project.website.settings
Please help me debug this.
I had the some problem. From within sa2 try
from sa2.models import Mo1, Mo2, Mo3
or alternatively
from .models import Mo1, Mo2, Mo3
CATCH: be sure to use the same imports in your forms.py, tests.py or wherever else you import those models. If you update only one of the import it will not work and you will still get the same error.
The problem occurs because of a double import. For more information please see this : The Double Import Trap
Good luck
P.S. no __init__.py were hurt in the process
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With