user1592380
user1592380

Reputation: 36347

django : LookupError: App ' doesn't have a 'models' model

enter image description here

I'm working through https://bixly.com/blog/awesome-forms-django-crispy-forms/ , trying to set up a bootstrap 3 form using django crispy forms.

in app1/models.py, I have set up my form:

from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth.models import AbstractUser
from django import forms


class User(AbstractUser):

    # Address
    contact_name = models.CharField(max_length=50)
    contact_address = models.CharField(max_length=50)
    contact_email = models.CharField(max_length=50)
    contact_phone = models.CharField(max_length=50)
    ......

Please note I have not created any db tables yet. I don't need them at this stage. I'm just trying to get the forms working. When I run this I get:

Performing system checks...

Unhandled exception in thread started by <function wrapper at 0x02B63EF0>
Traceback (most recent call last):
  File "C:\lib\site-packages\django\utils\autoreload.py", line 222, in wrapper
    fn(*args, **kwargs)
  File "C:\lib\site-packages\django\core\management\commands\runserver.py", line 105, in inner_run
    self.validate(display_num_errors=True)
  File "C:\lib\site-packages\django\core\management\base.py", line 362, in validate
    return self.check(app_configs=app_configs, display_num_errors=display_num_errors)
  File "C:\lib\site-packages\django\core\management\base.py", line 371, in check
    all_issues = checks.run_checks(app_configs=app_configs, tags=tags)
  File "C:\lib\site-packages\django\core\checks\registry.py", line 59, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\lib\site-packages\django\contrib\auth\checks.py", line 12, in check_user_model
    cls = apps.get_model(settings.AUTH_USER_MODEL)
  File "C:\lib\site-packages\django\apps\registry.py", line 202, in get_model
    return self.get_app_config(app_label).get_model(model_name.lower())
  File "C:\lib\site-packages\django\apps\config.py", line 166, in get_model
    "App '%s' doesn't have a '%s' model." % (self.label, model_name))
LookupError: App 'app1' doesn't have a 'models' model.

How can I fix this?

Upvotes: 1

Views: 5206

Answers (1)

Alasdair
Alasdair

Reputation: 309099

The AUTH_USER_MODEL settings should be of the form <app name>.<model>. Your model name is User, not model, so your setting should be:

AUTH_USER_MODEL = 'app1.User'

You should also remove the following User import from your models.py. You only have to import AbstractUser.

from django.contrib.auth.models import User

Upvotes: 6

Related Questions