User models of users in Django: `no such table: auth_user`

In response to the previous question, I edited the django registration module with the following changes:

in myapp/models.py:

from django.contrib.auth.models import UserManager
from django.contrib.auth.models import AbstractUser

class AccountManager(UserManager):
    def create_user(self, email, password=None, **kwargs):
        if not email:
            raise ValueError('Users must have a valid email address.')
        if not kwargs.get('username'):
            raise ValueError('Users must have a valid username.')

        account = self.model(
            email=self.normalize_email(email), 
            username=kwargs.get('username'), 
            #year_of_birth = kwargs.get('year_of_birth'),
            #MODEL = kwargs.get('MODEL_NAME'),
        )
        account.set_password(password)
        account.save()

        return account

    def create_superuser(self, email, password, **kwargs):
        account = self.create_user(email, password, **kwargs)
        account.is_staff = True
        account.is_superuser = True
        account.save()

        return account

class Account(AbstractUser):
    #email = models.EmailField(unique=True)
    points = models.FloatField(default = 100.0)
    #ADD YOUR MODELS HERE

    objects = AccountManager()

    def __str__(self):
        return "Account: "+self.username

and in myproject/settings.py:

AUTH_USER_MODEL = 'myapp.Account'

the rest of the application now works (i.e. refers to Account, which also has base fields from the model User). However, the module itself django-registrationdoes not work. When I submit a new registration form (with username, email and password), I get an error message:

OperationalError at /accounts/register/
no such table: auth_user

I tried many combinations makemigrationsand migrate(also with --fakeand arguments --fake-initial), but (I think) the table is authnot initialized with the new settings.

, Account, auth User <? p >

,

, , :

>>> from django.contrib.auth.models import User
>>> users = User.objects.all()
AttributeError: Manager isn't available; User has been swapped for 'myapp.Account'

, , Account User. , auth_user? ​​ settings.py?

0
1

, , . , , ,

+1

Source: https://habr.com/ru/post/1658553/


All Articles