citusdata / citusdata/django-multitenant

django.db.utils.ProgrammingError: there is no unique constraint matching given keys for referenced table "accounts_user"

Open
#129 8 comments 0 reactions 0 assignees View on GitHub
migration needs clarification
Dominant language
Python
Stars
823
Forks
126
PR merge metrics
No merged PRs in 30d

Description

Facing issue while migrating

`psycopg2.errors.InvalidForeignKey: there is no unique constraint matching given keys for referenced table "accounts_user"

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/var/www/html/Kapsus-eCom-SAAS/manage.py", line 22, in
main()
File "/var/www/html/Kapsus-eCom-SAAS/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/core/management/__init__.py", line 425, in execute_from_command_line
utility.execute()
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/core/management/__init__.py", line 419, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/core/management/base.py", line 373, in run_from_argv
self.execute(*args, **cmd_options)
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/core/management/base.py", line 417, in execute
output = self.handle(*args, **options)
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/core/management/base.py", line 90, in wrapped
res = handle_func(*args, **kwargs)
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 253, in handle
post_migrate_state = executor.migrate(
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/db/migrations/executor.py", line 126, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/db/migrations/executor.py", line 156, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/db/migrations/executor.py", line 235, in apply_migration
with self.connection.schema_editor(atomic=migration.atomic) as schema_editor:
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/db/backends/base/schema.py", line 126, in __exit__
self.execute(sql)
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django_multitenant/backends/postgresql/base.py", line 118, in execute
super(DatabaseSchemaEditor, self).execute(statement)
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/db/backends/base/schema.py", line 153, in execute
cursor.execute(sql, params)
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/db/backends/utils.py", line 99, in execute
return super().execute(sql, params)
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute
with self.db.wrap_database_errors:
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/var/www/html/Kapsus-eCom-SAAS/kes_env/lib/python3.10/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: there is no unique constraint matching given keys for referenced table "accounts_user"
`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.