I\'m at wit\'s end. After a dozen hours of troubleshooting, probably more, I thought I was finally in business, but then I got:
Model class django.contrib.co
I got this error on importing models in tests, i.e. given this Django project structure:
|-- myproject
|-- manage.py
|-- myproject
|-- myapp
|-- models.py # defines model: MyModel
|-- tests
|-- test_models.py
in file test_models.py
I imported MyModel
in this way:
from models import MyModel
The problem was fixed if it is imported in this way:
from myapp.models import MyModel
Hope this helps!
PS: Maybe this is a bit late, but I not found in others answers how to solve this problem in my code and I want to share my solution.
If you have got all the config right, it might just be an import mess. keep an eye on how you are importing the offending model.
The following won't work from .models import Business
. Use full import path instead: from myapp.models import Business
The issue is that:
You have made modifications to your models file, but not addedd them yet to the DB, but you are trying to run Python manage.py runserver.
Run Python manage.py makemigrations
Python manage.py migrate
Now Python manage.py runserver and all should be fine.
I got this one when I used ./manage.py shell
then I accidentally imported from the root project level directory
# don't do this
from project.someapp.someModule import something_using_a_model
# do this
from someapp.someModule import something_using_a_model
something_using_a_model()