[Django]-'User' object has no attribute 'username'

6๐Ÿ‘

โœ…

You are most likely when Django packages which rely on Django 1.4-like models where User object always has an username field. The issue is either in your own code or third party code, but the question does not has enough details to tell.

  • Use a full traceback to trace these addons

  • Update them if patched package is available

  • If there is no patch available you need to fork and patch the third party code yourself

About Django 1.5+ user model:

https://docs.djangoproject.com/en/stable/topics/auth/customizing/#auth-custom-user

You should most likely user id to identify the user, not username

๐Ÿ‘คMikko Ohtamaa

1๐Ÿ‘

I had this problem too, what solved it was to use AbstractUser instead of AbstractBaseUser.

Then do a proper migrations so the database has the right attribute. Your code can be okay, but you will still have the error if your database is not up to date.

I say migration but it would probably be a lot easier (or the only way) to just destroy the db and start from scratch.

0๐Ÿ‘

AUTH_USER_MODEL = User

add a:

class User(AbstractBaseUser):

    username = models.CharField(max_length=100)
๐Ÿ‘คJEnriquePS

Leave a comment