[Answered ]-Line 158, in get_app_config return self.app_configs[app_label] KeyError: 'account'

1👍

As indicated by @willeM_Van Onsem, it turns out that

AUTH_USER_MODEL refers to model 'account.User' that has not been installed

because it’s not account, but accounts.

So I substituted

AUTH_USER_MODEL = 'account.User'

with

AUTH_USER_MODEL = 'accounts.User'

Also, in class User,

class User(AbstractBaseUser):
    email = models.EmailField(max_length=255, unique=True)
    # full_name = models.CharField(max_length=255, blank=True, null=True)
    active = models.BooleanField(default=True)  # is h* allowed to login?
    staff = models.BooleanField(default=False) # staff user, not superuser
    admin = models.BooleanField(default=False) # superuser
    timestamp = models.DateTimeField(auto_now_add=True) # superuser

this line is referring to a non-existing field username

USERNAME_FIELD = 'username'

So I turned the line into

USERNAME_FIELD = 'email'

Furthermore, as indicated in this thread, I have changed

objects = UserManager

to

objects = UserManager()

otherwise one would get the error

    self.UserModel._default_manager.db_manager(database).get_by_natural_key(
AttributeError: 'Manager' object has no attribute 'get_by_natural_key'

Then I have run python manage.py makemigrations, manually inserted a default value timezone.now when asked by django

It is impossible to add the field 'timestamp' with 'auto_now_add=True' to user without providing a default. This is because the database needs something to populate existing rows.

 1) Provide a one-off default now which will be set on all existing rows
 2) Quit and manually define a default value in models.py.
Select an option: 1
Please enter the default value as valid Python.
Accept the default 'timezone.now' by pressing 'Enter' or provide another value.
The datetime and django.utils.timezone modules are available, so it is possible to provide e.g. timezone.now as a value.
Type 'exit' to exit this prompt
[default: timezone.now] >>> timezone.now

so that the migration went fine

Migrations for 'accounts':
  accounts/migrations/0004_user_timestamp_profile.py
    - Add field timestamp to user
    - Create model Profile

and in the end I run

python manage.py migrate
👤Tms91

Leave a comment