Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

django.db.utils.ProgrammingError: Multiple primary keys for table «django_rest_passwordreset_resetpasswordtoken» are not allowed. #8

Closed
iagocanalejas opened this issue Sep 14, 2018 · 14 comments
Assignees

Comments

@iagocanalejas
Copy link
Contributor

Hi, after updating from version 0.9.4 to 0.9.5 i am getting a django.db.utils.ProgrammingError: Multiple primary keys for table «django_rest_passwordreset_resetpasswordtoken» are not allowed. trying to do a manage.py migrate.

I don't really know what information you would need to track this issue but i would love to collaborate with you to fix this issue so feel free to ask for whatever context information you would need.

  File "manage.py", line 31, in <module>
    execute_from_command_line(sys.argv)
  File "\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line

    utility.execute()
  File "\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "\venv\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "\venv\lib\site-packages\django\core\management\base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "\venv\lib\site-packages\django\core\management\base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "\venv\lib\site-packages\django\core\management\commands\migrate.py", line 203, in handle
    fake_initial=fake_initial,
  File "\venv\lib\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 "\venv\lib\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 "\venv\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "\venv\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "\venv\lib\site-packages\django\db\migrations\operations\fields.py", line 216, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "\venv\lib\site-packages\django\db\backends\base\schema.py", line 523, in alter_field
    old_db_params, new_db_params, strict)
  File "\venv\lib\site-packages\django\db\backends\postgresql\schema.py", line 122, in _alter_field
    new_db_params, strict,
  File "\venv\lib\site-packages\django\db\backends\base\schema.py", line 719, in _alter_field
    "columns": self.quote_name(new_field.column),
  File "\venv\lib\site-packages\django\db\backends\base\schema.py", line 133, in execute
    cursor.execute(sql, params)
  File "\venv\lib\site-packages\django\db\backends\utils.py", line 100, in execute
    return super().execute(sql, params)
  File "\venv\lib\site-packages\django\db\backends\utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "\venv\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "\venv\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "\venv\lib\site-packages\django\db\utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "\venv\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: Multiple primary keys for table «django_rest_passwordreset_resetpasswordtoken» are not allowed.
@ChristianKreuzberger
Copy link
Collaborator

Hi!

This is most caused by my "fix" for issue #4.
I introduced a new primary key, but it seems like I messed up the order within the migration
https://github.com/anx-ckreuzberger/django-rest-passwordreset/blob/35f33088cf7d004411302b81c1534785610b0138/django_rest_passwordreset/migrations/0002_pk_migration.py#L35-L46

I'll see if I can fix this asap.

@ChristianKreuzberger
Copy link
Collaborator

ChristianKreuzberger commented Sep 14, 2018

I tried to reproduce the issue, but I couldn't (using sqlite). Can you let me know what database (+ version) you are using (from what I've found out based on the bug, you seem to be using Postgres)?

@iagocanalejas
Copy link
Contributor Author

Yep, Postgres 9.6

@ChristianKreuzberger
Copy link
Collaborator

I've looked into this, and I wasn't able to reproduce this issue (yet).

Which version of psycopg2 are you using (pip freeze would help too)?

@RonKbS
Copy link

RonKbS commented Oct 2, 2018

Hello,

I've just come across the same error.
psycopg2==2.7.5 is the version on my end.

@iagocanalejas
Copy link
Contributor Author

Same version here (psycopg2==2.7.5), will add a pip freeze when i get come

@iagocanalejas
Copy link
Contributor Author

Sorry for late answer, being busy. Here is my pip freeze:

altgraph==0.15
argon2-cffi==18.1.0
beautifulsoup4==4.6.3
boto3==1.9.11
botocore==1.12.11
certifi==2018.1.18
cffi==1.11.5
chardet==3.0.4
coreapi==2.3.3
coreschema==0.0.4
coverage==4.5.1
Django==2.1.1
django-admin-honeypot==1.1.0
django-cors-headers==2.4.0
django-guardian==1.4.9
django-modeltranslation==0.13b1
django-money==0.14.3
django-oauth-toolkit==1.2.0
django-rest-passwordreset==0.9.4
django-rosetta==0.9.0
django-stdimage==4.0.0
django-storages==1.7.1
djangorestframework==3.8.2
djangorestframework-recursive==0.1.2
docutils==0.14
drf-yasg==1.10.2
future==0.16.0
idna==2.6
inflection==0.3.1
itypes==1.1.0
Jinja2==2.10
jmespath==0.9.3
jsonschema==2.6.0
MarkupSafe==1.0
microsofttranslator==0.8
mock==2.0.0
oauthlib==2.0.7
openapi-codec==1.3.2
pbr==4.0.2
Pillow==5.2.0
polib==1.1.0
progressbar2==3.37.1
psycopg2==2.7.5
psycopg2-binary==2.7.5
py-moneyed==0.7.0
pycparser==2.18
python-dateutil==2.7.2
python-memcached==1.59
python-utils==2.3.0
pytz==2018.4
requests==2.18.4
ruamel.yaml==0.15.37
s3transfer==0.1.13
six==1.11.0
stdlib-list==0.4.0
uritemplate==3.0.0
urllib3==1.22

@anx-ckreuzberger
Copy link
Contributor

This is an issue with Django Version 2.1 (probably also 2.0). It works fine with Django 1.11.*.

I will see if I can fix this issue easily...

@anx-ckreuzberger
Copy link
Contributor

I believe this is related to an unintended breaking change introduced with Django 2.1, see Django Issue #29790.

Nevertheless, I believe that I managed to fix this issue with version 0.9.6 which I just released on pypi.

I also added Django 2.1 to the list of compatible versions as well as travis-ci/tox tests.

I believe that this change should not have a negative impact on users that have already ran the migration.

@iagocanalejas
Copy link
Contributor Author

Works fine men thank you

@mmoravcik
Copy link

mmoravcik commented Oct 16, 2018

I've just installed the 0.9.6 version and got this while running migrations (Postgres 9.6.2):

  Applying django_rest_passwordreset.0001_initial... OK
  Applying django_rest_passwordreset.0002_pk_migration...Traceback (most recent call last):
  File "/users/.virtualenvs/some/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: multiple primary keys for table "django_rest_passwordreset_resetpasswordtoken" are not allowed

UPDATE: this works with Django 2.1.2 but doesn't with 2.0.7

@anx-ckreuzberger
Copy link
Contributor

anx-ckreuzberger commented Oct 17, 2018

So it works with 2.1 but not 2.0 now... Gotta love migrations!

I'm reopening and renaming this, and I'll add a note to the readme.

edit: Also does not work with 1.11 with the "new" migration...

anx-ckreuzberger added a commit that referenced this issue Oct 17, 2018
migrations broke again, but now for django 1.11 and 2.0
anx-ckreuzberger added a commit that referenced this issue Oct 17, 2018
migrations broke again, but now for django 1.11 and 2.0
@anx-ckreuzberger
Copy link
Contributor

I've just released version 0.9.7 on pypi, that should be compatible with Django 1.11, 2.0 and 2.1.

https://github.com/anx-ckreuzberger/django-rest-passwordreset/blob/34b66f92a2dea6b484beb8a24cd9ffefd6cb6d7e/django_rest_passwordreset/migrations/0002_pk_migration.py#L70-L92

I'm not particularly happy with that... but as long as it works :D

@anx-ckreuzberger
Copy link
Contributor

Seeing that there are no more problems with this, I'll close it with the solution that we currently have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants