0

I added this line in my settings.py file in order to make a custom User model the auth_user database: AUTH_USER_MODEL = 'main.User' (main is the name of one my apps and it contains all of the models).

But I later found out that I should have done this before the initial migration so when I tried to integrate Google Authentication in the admin page I received this error that stated that my auth_user table was empty (something about it not having any records with an id of 1).

So I tried deleting the migrations and returning the database to its state before the migrations but I always had an error like this: ValueError: The field socialaccount.SocialAccount.user was declared with a lazy reference to 'main.user', but app 'main' isn't installed.

I tried fixing this by following the adive on this article and cleared my postgresql database along with migration files and pycache. After this I tried to makemigrations and received this error: ValueError: The field socialaccount.SocialAccount.user was declared with a lazy reference to 'auth.user', but app 'auth' isn't installed.. And then this error when I tried to migrate: django.db.utils.ProgrammingError: relation "main_user" does not exist.

I have tried searching for solutions but I cannot find anything. What do I do?

settings.py (not all of it)

INSTALLED_APPS = [
    'landing',
    'main',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites', 
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
]

TEMPLATES = [
    {
        'DIRS': [
            os.path.join(BASE_DIR, 'landing', 'frontend', 'build'),
            os.path.join(BASE_DIR, 'landing', 'templates'),
            os.path.join(BASE_DIR, 'main', 'frontend', 'dist'),
        ],
        # ...
    },
]

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        # ...
    }
}

AUTH_USER_MODEL = 'main.User'

STATICFILES_DIRS = [
    # ...
]

AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend'
]

SITE_ID = 1
LOGIN_REDIRECT_URL = '/'

# Additional configuration settings
SOCIALACCOUNT_QUERY_EMAIL = True
ACCOUNT_LOGOUT_ON_GET= True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_EMAIL_REQUIRED = True

SOCIALACCOUNT_PROVIDERS = {
    'google': {
        'SCOPE': [
            'profile',
            'email',
        ],
        'AUTH_PARAMS': {
            'access_type': 'online',
        }
    }
}
Tices
  • 13
  • 5

1 Answers1

0

I found a solution on this answer.

I had already undone all migrations, deleted all /migration files and cleared all the data in my database. So to solve the main_user and main.User bugs I just had to makemigrations seperately with the main app by running:

python manage.py makemigrations main

And then migrate all the changes:

python manage.py migrate

This removed all the bugs I received previously and allowed me to connect Google Authentication with no further issues.

Tices
  • 13
  • 5