33đź‘Ť
âś…
from django.db import models
from django.contrib.auth.models import User
class Topic(models.Model):
user = models.ForeignKey(User)
'auth.User'
would have worked, too. It’s not Python’s library syntax, it’s the Django ORM’s “app.model” syntax. But you should only pass the model as a string if you’re desperately trying to solve a circular dependency. And if you have a circular dependency, your code is eff’d.
👤Elf Sternberg
7đź‘Ť
Even I faced same issue,
The error message is clear: you haven’t installed the User model.
Add "django.contrib.auth" to INSTALLED_APPS in your settings.py.
That all..Hope it will solve this issue, worked fine for me.
👤Abdul Rafi
- How to store google oauth token in django : Storage or database
- Bulk, partial updates with Django Rest Framework
- AttributeError: 'property' object has no attribute 'admin_order_field'
- Import RelatedManager from django.db.models.fields.related
1đź‘Ť
I had the same error, but in different situation.
I splitted the models.py in two files:
myapp/
models/
__init__.py
foo.py
bar.py
In foo.py I had two models:
class Foo(models.Model):
attr1 = ... etc
class FooBar(models.Model):
other = ... etc
foo = models.ForeignKey(Foo)
class Meta():
app_label = 'foo'
I solved adding Meta also in Foo model:
class Foo(models.Model):
attr1 = ... etc
class Meta():
app_label = 'foo'
👤Griffosx
- Django doesn't create translation .po files
- Django-mptt and multiple parents?
- Celery chaining tasks sequentially
- Django: datetime filter by date ignoring time
- Passing arguments to management.call_command on a django view
Source:stackexchange.com