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
as a noob using Python3 ,I find it might be an import error instead of a Django error
wrong:
from someModule import someClass
right:
from .someModule import someClass
this happens a few days ago but I really can't reproduce it...I think only people new to Django may encounter this.here's what I remember:
try to register a model in admin.py:
from django.contrib import admin
from user import User
admin.site.register(User)
try to run server, error looks like this
some lines...
File "/path/to/admin.py" ,line 6
tell you there is an import error
some lines...
Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label
change user
to .user
,problem solved
For PyCharm users: I had an error using not "clean" project structure.
Was:
project_root_directory
└── src
├── chat
│ ├── migrations
│ └── templates
├── django_channels
└── templates
Now:
project_root_directory
├── chat
│ ├── migrations
│ └── templates
│ └── chat
├── django_channels
└── templates
Here is a lot of good solutions, but I think, first of all, you should clean your project structure or tune PyCharm Django settings before setting DJANGO_SETTINGS_MODULE
variables and so on.
Hope it'll help someone. Cheers.
I've got a similar error while building an API in Django rest_framework.
RuntimeError: Model class apps.core.models.University doesn't declare an explicit > app_label and isn't in an application in INSTALLED_APPS.
luke_aus's answer helped me by correcting my urls.py
from
from project.apps.views import SurgeryView
to
from apps.views import SurgeryView
After keep on running into this issue and keep on coming back to this question I thought I'd share what my problem was.
Everything that @Xeberdee is correct so follow that and see if that solves the issue, if not this was my issue:
In my apps.py this is what I had:
class AlgoExplainedConfig(AppConfig):
name = 'algo_explained'
verbose_name = "Explain_Algo"
....
And all I did was I added the project name in front of my app name like this:
class AlgoExplainedConfig(AppConfig):
name = '**algorithms_explained**.algo_explained'
verbose_name = "Explain_Algo"
and that solved my problem and I was able to run the makemigrations and migrate command after that! good luck
I got this error while trying to upgrade my Django Rest Framework app to DRF 3.6.3 and Django 1.11.1.
For anyone else in this situation, I found my solution in a GitHub issue, which was to unset the UNAUTHENTICATED_USER
setting in the DRF settings:
# webapp/settings.py
...
REST_FRAMEWORK = {
...
'UNAUTHENTICATED_USER': None
...
}
Most probably you have dependent imports.
In my case I used a serializer class as a parameter in my model, and the serializer class was using this model: serializer_class = AccountSerializer
from ..api.serializers import AccountSerializer
class Account(AbstractBaseUser):
serializer_class = AccountSerializer
...
And in the "serializers" file:
from ..models import Account
class AccountSerializer(serializers.ModelSerializer):
class Meta:
model = Account
fields = (
'id', 'email', 'date_created', 'date_modified',
'firstname', 'lastname', 'password', 'confirm_password')
...