'Migrating my Django project on Heroku is showing django.db.utils.ProgrammingError: relation "users_customuser" does not exist
Migrating my Django project on Heroku is showing django.db.utils.ProgrammingError: relation "users_customuser" does not exist. But this is working completely fine on my local.
Running migrations: Applying account.0001_initial...Traceback (most recent call last): File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute return self.cursor.execute(sql, params) psycopg2.errors.UndefinedTable: relation "users_customuser" does not exist
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/app/manage.py", line 22, in <module>
main()
File "/app/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 244, in handle
post_migrate_state = executor.migrate(
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/migrations/executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/migrations/executor.py", line 230, in apply_migration
migration_recorded = True
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 118, in __exit__
self.execute(sql)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 145, in execute
cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "users_customuser" does not exist
I have even added AUTH_USER_MODEL = 'users.CustomUser' to my settings.py. I have added my app in the INSTALLED_APPS.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# 3rd Party Apps
'rest_framework', # new
'rest_framework.authtoken', # new
'rest_auth', # new
'django.contrib.sites', # new
'allauth', # new
'allauth.account', # new
'allauth.socialaccount', # new
'rest_auth.registration', # new
'corsheaders', # new
# Local Apps
'users.apps.UsersConfig', # new
'post.apps.PostConfig',
'newsData.apps.NewsdataConfig',
]
Here is my models.py file.
from django.contrib.auth.models import AbstractUser
from django.db import models
import os
from .storage import OverwriteStorage
class CustomUser(AbstractUser):
def __str__(self):
return self.email
class Profile(models.Model):
user = models.OneToOneField(CustomUser , on_delete=models.CASCADE , related_name='profile')
handleName = models.CharField(max_length=20, null = True , blank=True)
primaryColor = models.CharField(max_length=7, default="#00ff00")
secondaryColor = models.CharField(max_length=7, default="#ff0000")
logoImage = models.ImageField(default = 'defaultLogo.png' , storage=OverwriteStorage(), upload_to='images/img/test/logoImage.png')
tempImage1 = models.ImageField(default = 'tempImage1.png' ,storage=OverwriteStorage(), upload_to='images/img/test/tempImage1.png')
tempImage2 = models.ImageField(default = 'tempImage2.png' ,storage=OverwriteStorage(), upload_to='images/img/test/tempImage2.png')
tempImage3 = models.ImageField(default = 'tempImage3.png' ,storage=OverwriteStorage(), upload_to='images/img/test/tempImage3.png')
telegramToken = models.CharField(max_length=200, null = True , blank=True)
def __str__(self):
return f'{self.user.username} Profile'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
