Why Getting (user.models.DoesNotExist: CustomUser matching query does not exist.)? - python

I have create two models CustomUser inheriting AbstractUser and UserProfile, and there is OneToOne relation between them.
then i run the following command:-
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
When i run the command for createsuperuser, i got error as bellow:-(model are posted in the end..)
PS C:\Users\akcai\OneDrive\Desktop\deep_Stuffs\git_cloned\PollingApplication> python manage.py createsuperuser
Email: admin#gmail.com
Name: admin
Username: admin
Password:
Password (again):
The password is too similar to the username.
This password is too short. It must contain at least 8 characters.
This password is too common.
Bypass password validation and create user anyway? [y/N]: y
profile create too..
Traceback (most recent call last):
File "C:\Users\akcai\OneDrive\Desktop\deep_Stuffs\git_cloned\PollingApplication\manage.py", line 22, in <module>
main()
File "C:\Users\akcai\OneDrive\Desktop\deep_Stuffs\git_cloned\PollingApplication\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\akcai\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\akcai\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\akcai\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\akcai\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 79, in execute
return super().execute(*args, **options)
File "C:\Users\akcai\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Users\akcai\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 189, in handle
self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
File "C:\Users\akcai\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\models.py", line 163, in create_superuser
return self._create_user(username, email, password, **extra_fields)
File "C:\Users\akcai\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\models.py", line 146, in _create_user
user.save(using=self._db)
File "C:\Users\akcai\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\base_user.py", line 67, in save
super().save(*args, **kwargs)
File "C:\Users\akcai\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\base.py", line 726, in save
self.save_base(using=using, force_insert=force_insert,
File "C:\Users\akcai\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\base.py", line 774, in save_base
post_save.send(
File "C:\Users\akcai\AppData\Local\Programs\Python\Python39\lib\site-packages\django\dispatch\dispatcher.py", line 180, in send
return [
File "C:\Users\akcai\AppData\Local\Programs\Python\Python39\lib\site-packages\django\dispatch\dispatcher.py", line 181, in <listcomp>
(receiver, receiver(signal=self, sender=sender, **named))
File "C:\Users\akcai\OneDrive\Desktop\deep_Stuffs\git_cloned\PollingApplication\user\models.py", line 27, in CreateProfile
user = CustomUser.objects.get(username=instance)
File "C:\Users\akcai\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\akcai\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\query.py", line 435, in get
raise self.model.DoesNotExist(
user.models.DoesNotExist: CustomUser matching query does not exist.
PS C:\Users\akcai\OneDrive\Desktop\deep_Stuffs\git_cloned\PollingApplication>
models.py:-
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.db.models.signals import post_save
# Create your models here.
class CustomUser(AbstractUser):
email = models.EmailField(max_length=250, null=False, unique=True)
name = models.CharField(max_length=50, null=False)
username = models.CharField(max_length=50, null=False)
password = models.CharField(max_length=15, null=False)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['name', 'username']
class UserProfile(models.Model):
user = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
def get_all_polls(self):
from polls.models import PollQuestion
pass
def CreateProfile(sender, instance, **kwargs):
print("profile create too..")
user = CustomUser.objects.get(username=instance)
UserProfile.objects.create(user=user)
post_save.connect(CreateProfile, sender=CustomUser)
# following = models.ManyToManyField(CustomUser, symmetrical=False, null=True)
after this i tried to login to admin portal and get:- CustomUser matching query does not exist.
After this i checked the db is there any user exist or not:-
>>> from user.models import CustomUser
>>> u = CustomUser.objects.get(id=1)
>>> vars(u)
{'_state': <django.db.models.base.ModelState object at 0x000001C3C5B4CCA0>, 'id': 1, 'last_login': datetime.datetime(2021, 9, 21, 6, 43, 56, 565960, tzinfo=<UTC>), 'is_superuser': True, 'first_name': '', 'last_name': '', 'is_staff': True, 'is_active': True, 'date_joined': datetime.datetime(2021, 9, 21, 6, 28, 44, 123074, tzinfo=<UTC>), 'email': 'admin#gmail.com', 'name': 'admin', 'username': 'admin', 'password': 'pbkdf2_sha256$260000$SP9TyZ6VOMIFlRwvuvmDn4$7sak8fWf7QMTPfefoPMyQpLjYk3XpumRaJ5MMxq2lH4='}
>>>
I am unable to figure out on my own, what i am doing wrong, please help to get out of this rid.
Hope to here from you soon..
Thanks in advance...

user = CustomUser.objects.get(username=instance)
makes little sense.
You're trying to get an user by querying whether their username equals an instance (of CustomUser).
This will cause Django to stringify the CustomUser, so your query ends up something like (if SQL were Python)
if username == "<CustomUser: 3>":
which obviously will yield no rows.
In general, you should not need both a custom user model and a user profile model. Maybe rethink your database models so you only have your custom user model, and be sure to use the AUTH_USER_MODEL setting to wire it up.

Related

OperationalError at / no such table: users_user

I had a model Profile which was an extension to my User model which was the ForeignKey of my Post model, but I changed it to an AbstractUser and now if I try migrating or running and refreshing the page the server I get an error.
models.py
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
bio = models.TextField(max_length=500,null=True)
from django.db import models
from django.conf import settings
from django.urls import reverse
class Post(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True)
title = models.CharField(max_length=100)
content = models.TextField()
def get_absolute_url(self):
return reverse('post-details', kwargs={'pk': self.pk})
settings.py
INSTALLED_APPS = [
...
'posts',
'users',
]
AUTH_USER_MODEL = 'users.User'
error message after I try migrating
Apply all migrations: admin, auth, contenttypes, posts, sessions, users
Traceback (most recent call last):
File "/home/user/Projects/DNF/Project/manage.py", line 22, in <module>
main()
File "/home/user/Projects/DNF/Project/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.10/dist-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/base.py", line 448, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/base.py", line 96, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/commands/migrate.py", line 295, in handle
pre_migrate_apps = pre_migrate_state.apps
File "/usr/local/lib/python3.10/dist-packages/django/utils/functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.10/dist-packages/django/db/migrations/state.py", line 566, in apps
return StateApps(self.real_apps, self.models)
File "/usr/local/lib/python3.10/dist-packages/django/db/migrations/state.py", line 637, in __init__
raise ValueError("\n".join(error.msg for error in errors))
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'users.user', but app 'users' doesn't provide model 'user'.
The field posts.Post.author was declared with a lazy reference to 'users.user', but app 'users' doesn't provide model 'user'.
The field users.Profile.user was declared with a lazy reference to 'users.user', but app 'users' doesn't provide model 'user'.
I easily solved it by deleting all the migration files in the migrations folder except the init.py file. And also delete db.sqlite3. Now run the following commands : python manage.py makemigrations and then python manage.py migrate. Now you'll have to create the super user once again, so for this just type the following commmand : python manage.py createsuperuser. Then it will prompt for username, email and password, so enter your credentials and all will continue to work properly once again I hope that this will be helpful.
try to directly reference the User model, not through settings
change the foreign key field to this:
author = models.ForeignKey("users.User", on_delete=models.CASCADE, null=True)
To have a reference to the User model, you should not do through settings directly instead you can use get_user_model() function. This function will return the currently active User model of project( the custom User model if one is specified, or User otherwise).
So change the foreign key field of your Post model like below:
from django.db import models
from django.conf import settings
from django.urls import reverse
from django.contrib.auth import get_user_model
User = get_user_model()
class Post(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
...
Reference: get_user_model() [Django-doc]

not able to createsuperuser in django

I am not able to createsuperuser, I am getting the following error
Django Version 3.1.1
Traceback (most recent call last):
File "/Users/napoleon/django-app/mysite/manage.py", line 22, in <module>
main()
File "/Users/napoleon/django-app/mysite/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/napoleon/django-app/pfs-venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/Users/napoleon/django-app/pfs-venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/napoleon/django-app/pfs-venv/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/napoleon/django-app/pfs-venv/lib/python3.9/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 79, in execute
return super().execute(*args, **options)
File "/Users/napoleon/django-app/pfs-venv/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/Users/napoleon/django-app/pfs-venv/lib/python3.9/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 189, in handle
self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
AttributeError: 'UserManager' object has no attribute 'create_superuser'
basically its throwing
AttributeError: 'UserManager' object has no attribute 'create_superuser'
I read this alsoSO-related question I don't get it exactly as conveyed there.
Custom User models mainapp/models.py
import uuid
from django.contrib.auth.models import AbstractUser, UserManager
from django.db import models
class CustomUserManager(UserManager):
def create_user(self, email,date_of_birth, username,password=None,):
if not email:
msg = 'Users must have an email address'
raise ValueError(msg)
if not username:
msg = 'This username is not valid'
raise ValueError(msg)
# if not date_of_birth:
# msg = 'Please Verify Your DOB'
# raise ValueError(msg)
# user = self.model( email=UserManager.normalize_email(email),
# username=username,date_of_birth=date_of_birth )
user = self.model( email=UserManager.normalize_email(email),
username=username )
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self,email,username,password,date_of_birth):
user = self.create_user(email,password=password,username=username,date_of_birth=date_of_birth)
user.is_admin = True
user.is_staff = True
user.is_superuser = True
user.save(using=self._db)
return user
# Custom User Model
class User(AbstractUser):
id = models.BigAutoField(primary_key=True)
user_uuid = models.UUIDField(default=uuid.uuid1())
full_name = models.CharField(max_length=200,default='')
email = models.CharField(max_length=200,default='')
#form can have empty value blank=True, db can have empty value null=True
email_last_verified_on = models.DateTimeField(null=True)
Settings.py
# Swapping the user model
AUTH_USER_MODEL = 'mainapp.User'
Please clarify, what am I missing ...
You need to add the UserManager to the User mode:
class User(AbstractUser):
# …
objects = CustomUserManager()
Without specifying the manager, it will fallback to the UserManager [Django-doc], not the CustomUserManager.

django custom user model gives me lazy reference error

My code is as shown below:
models/user.py
from __future__ import unicode_literals
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import (
AbstractBaseUser, PermissionsMixin,BaseUserManager
)
class UserManager(BaseUserManager):
def _create_user(self, email, password, **extra_fields):
"""
Creates and saves a User with the given email,and password.
"""
if not email:
raise ValueError('The given email must be set')
try:
with transaction.atomic():
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
except:
raise
def create_user(self, email, password=None, **extra_fields):
extra_fields.setdefault('is_staff', False)
extra_fields.setdefault('is_superuser', False)
return self._create_user(email, password, **extra_fields)
def create_superuser(self, email, password, **extra_fields):
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
return self._create_user(email, password=password, **extra_fields)
class User(AbstractBaseUser, PermissionsMixin):
"""
An abstract base class implementing a fully featured User model with
admin-compliant permissions.
"""
email = models.EmailField(max_length=40, unique=True)
first_name = models.CharField(max_length=30, blank=True)
last_name = models.CharField(max_length=30, blank=True)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
date_joined = models.DateTimeField(default=timezone.now)
objects = UserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name']
def save(self, *args, **kwargs):
super(User, self).save(*args, **kwargs)
return self
models/init.py
from user import User
settings.py
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'django.middleware.clickjacking.XFrameOptionsMiddleware'
]
AUTH_USER_MODEL = 'dashboard.User'
After this when I run python manage.py migrate, it gives me the following error:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 164, in handle
pre_migrate_apps = pre_migrate_state.apps
File "/usr/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/site-packages/django/db/migrations/state.py", line 218, in apps
return StateApps(self.real_apps, self.models)
File "/usr/local/lib/python2.7/site-packages/django/db/migrations/state.py", line 295, in __init__
raise ValueError("\n".join(error.msg for error in errors))
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'dashboard.user', but app 'dashboard' doesn't provide model 'user'.
The field authtoken.Token.user was declared with a lazy reference to 'dashboard.user', but app 'dashboard' doesn't provide model 'user'.
Is it because of improper jwt token configuration or user model?
Have you tried retrieving your User model with get_user_model?
from django.contrib.auth import get_user_model
User = get_user_model()

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

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?
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

Deploying Django app to Heroku

I am a beginner to Python/coding/web development, and am running into and error during deployment process.
I coded a matchmaking app using Python/Django. I am attempting to deploy this app using Heroku. I followed all the directions in terms of setting up server, initializing Git repo, created Profile, Gunicorn, etc. etc. etc.
I was able to git push heroku master.
However, when I actually try to sync my files into the database, it returns an error. I typed this: heroku run python manage.py make migrations.
I get the following error:
Running python manage.py migrate on ⬢ blooming-island-78995... up, run.1306
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 327, in execute
django.setup()
File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/app/directmessages/models.py", line 9, in <module>
user_obj = User.objects.get(username='ayaspencer')
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 381, in get
num = len(clone)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 240, in __len__
self._fetch_all()
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 1074, in _fetch_all
self._result_cache = list(self.iterator())
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 52, in __iter__
results = compiler.execute_sql()
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 848, in execute_sql
cursor.execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "auth_user" does not exist
LINE 1: ...user"."is_active", "auth_user"."date_joined" FROM "auth_user...
^
What does it mean by auth_user does not exist? Does this mean I need to create a superuser? I tried and it won't let me. When I do heroku run python manage.py createsuperuser, it gives me the exact same error.
Here is my models.py for Posting app
from django.db import models
from django.contrib.auth.signals import user_logged_in
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
def upload_location(instance, filename):
#extension = filename.split(".")[1]
location = str(instance.user.username)
return "%s/%s" %(location, filename)
class PostingMessageManager(models.Manager):
def get_num_unread_messages(self, user):
return super(PostingMessageManager, self).filter(read=False).count()
class PostMessage(models.Model):
subject = models.CharField(max_length=150)
body = models.CharField(max_length=3000)
service_being_requested = models.CharField(max_length=3000, null=True)
service_being_offered = models.CharField(max_length=3000, null=True)
sender = models.ForeignKey(User, related_name='sent_post_messages', null=True, blank=True)
receiver = models.ForeignKey(User, related_name='received_post_messages', null=True, blank=True)
sent = models.DateTimeField(auto_now_add=False, auto_now=False, null=True, blank=True)
read_at = models.DateTimeField(auto_now_add=False, auto_now=False, null=True, blank=True)
read = models.BooleanField(default=False)
parent = models.ForeignKey('self', related_name='parent_message', null=True, blank=True)
replied = models.BooleanField(default=False)
CERTIFIED = 'Yes'
NONCERTIFIED = 'No'
INDIFFERENT = 'Indifferent'
CERTIFICATION_CHOICES = (
(CERTIFIED, 'Yes'),
(INDIFFERENT,'Indifferent'),
)
CERTIFICATION_CHOICES_ME = (
(CERTIFIED, 'Yes'),
(NONCERTIFIED, 'No'),
)
should_they_be_certified = models.CharField(max_length=200,
choices=CERTIFICATION_CHOICES,
default=INDIFFERENT)
are_you_certified = models.CharField(max_length=200,
choices=CERTIFICATION_CHOICES_ME,
default=NONCERTIFIED)
def is_certified(self):
return self.should_they_be_certified in (self.CERTIFIED)
def dont_care(self):
return self.are_you_certified in (self.INDIFFERENT)
def iam_certified(self):
return self.are_you_certified in (self.CERTIFIED)
def __unicode__(self):
return self.body
objects = PostingMessageManager()
def get_absolute_url(self):
return (reverse('view_post_message', kwargs={'ps_id': self.id}))
class Meta:
ordering = ['-sent',]
def set_messages_in_session(sender, user, request, **kwargs):
post_message = PostMessage.objects.get_num_unread_messages(user)
request.session['post_num_of_messages'] = post_message
user_logged_in.connect(set_messages_in_session)
#class F(models.Model):
#certification = models.CharField(max_length=50, choices=CERTCHOICE)
#class Meta:
#model = PostMessage
#fields = ['certification']
Also, not sure if this will be of any help, but I did a search for clean_username and based on my readings from this Django custom user model in admin, relation "auth_user" does not exist
python2.7/site-packages/django/contrib/auth/backends.py:
123 return
124 user = None
125: username = self.clean_username(remote_user)
126
127 UserModel = get_user_model()
...
143 return user
144
145: def clean_username(self, username):
146 """
147 Performs any cleaning on the "username" prior to using it to get or
python2.7/site-packages/django/contrib/auth/middleware.py:
78 # persisted in the session and we don't need to continue.
79 if request.user.is_authenticated():
80: if request.user.get_username() == self.clean_username(username, request):
81 return
82 else:
..
94 auth.login(request, user)
95
96: def clean_username(self, username, request):
97 """
98 Allows the backend to clean the username, if the backend defines a
99: clean_username method.
100 """
101 backend_str = request.session[auth.BACKEND_SESSION_KEY]
102 backend = auth.load_backend(backend_str)
103 try:
104: username = backend.clean_username(username)
105: except AttributeError: # Backend has no clean_username method.
106 pass
107 return username
7 matches across 2 files
It seems you didn't migrate, can you try:
heroku run python manage.py migrate
And you don't have to heroku run python manage.py makemigrations since migration scripts are already there
try to run these two commands
heroku run python manage.py migrate auth
heroku run python manage.py migrate
I was stuck in the exact same problem for more than 4 days. Everything got fixed with me when I used Postgres instead of Sqlite, which you are presumably using because it's the default option that comes with django, so I recommend following this tutorial to use Postgres: Django Girls: Installing PostgreSQL
Good Luck!

Categories