I have recently changed my database from sqlite3 in django to postgresql as I prepare my app for production. After making changes in settings.py, I have tried making migrations and I am getting an error. After running python manage.py migrate --run-syncdb
I get the error below in the terminal
System check identified some issues:
WARNINGS:
users.Document.uploaded_at: (fields.W161) Fixed default value provided.
HINT: It seems you set a fixed date / time / datetime value as default for this field. This may not be what you want. If you want to have the current date as default, use `django.utils.timezone.now`
users.Order.amount: (fields.W122) 'max_length' is ignored when used with IntegerField.
HINT: Remove 'max_length' from field
users.buyer.uploaded_at: (fields.W161) Fixed default value provided.
HINT: It seems you set a fixed date / time / datetime value as default for this field. This may not be what you want. If you want to have the current date as default, use `django.utils.timezone.now`
Operations to perform:
Synchronize unmigrated apps: channels, chatapp, crispy_forms, messages, payments, staticfiles, users
Apply all migrations: admin, auth, contenttypes, sessions
Synchronizing apps without migrations:
Creating tables...
Creating table users_user
Creating table users_document
Creating table users_buyer
Creating table users_category
Creating table users_service
Creating table users_profile
Creating table users_gig
Creating table users_order
Creating table users_product
Running deferred SQL...
Traceback (most recent call last):
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "auth_group" does not exist
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 214, in handle
self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 353, in sync_apps
self.stdout.write(' Running deferred SQL...')
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 118, in __exit__
self.execute(sql)
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 145, in execute
cursor.execute(sql, params)
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/kiprono/anaconda3/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "auth_group" does not exist
In my models.py, I have used the AbstractUser model. And here is my database in settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'demo',
'USER': 'demouser',
'PASSWORD': '12345678',
'HOST': 'localhost',
'PORT': '',
}
}
Any help will be highly appreciated. Thanks.
CodePudding user response:
The error message "relation auth_group
does not exist" suggests that Django is trying to run a migration that references the auth_group
table, but that table does not exist in your database. This could be because the auth app's initial migration has not been applied, or because the auth_group
table was removed from the database.
To fix this issue, you may need to apply the initial migrations for the auth app. You can do this by running the following command:
python manage.py migrate auth
If this does not solve the issue, you may need to delete any pending migrations and recreate them. You can do this by running the following commands:
python manage.py migrate auth zero
python manage.py makemigrations auth
python manage.py migrate auth