anexia-it / django-rest-passwordreset

An extension of django rest framework, providing a configurable password reset strategy
BSD 3-Clause "New" or "Revised" License
419 stars 148 forks source link

IntegrityError at /api/password_reset/ null value in column "id" of relation "django_rest_passwordreset_resetpasswordtoken" violates not-null constraint #164

Closed shubh010 closed 11 months ago

shubh010 commented 2 years ago

null value in column "id" of relation "django_rest_passwordreset_resetpasswordtoken" violates not-null constraint DETAIL: Failing row contains (2022-08-18 04:56:49.334713+00, 5e47cb425ce5db35388725370cb3dbf4e964245e, 49.204.165.2, Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KH..., 11, null).

farooq-oneclout commented 2 years ago

Same error as above when using django==4.1 and django-rest-passwordreset == 1.2.1

shubh010 commented 2 years ago

Same error as above when using django==4.1 and django-rest-passwordreset == 1.2.1

Did you get a fix

farooq-oneclout commented 2 years ago

Same error as above when using django==4.1 and django-rest-passwordreset == 1.2.1

Did you get a fix

yes by downgrading the version of django from 4.1 to 3. django password reset works on django < 4.0

shubh010 commented 2 years ago

Is there any other way I can get it to work on django 4.1

Collederas commented 2 years ago

I think this happens due to changes to AutoField in Django 4.1. I was able to solve this issue simply by deleting existing migrations and regenerating them.

I see there is already a MR doing something similar here, non destructively: https://github.com/anexia-it/django-rest-passwordreset/pull/162

nezhar commented 2 years ago

Good point, I will upgrade SnyPy to Django 4.1 and look deeper into this :wink:

shubh010 commented 2 years ago

I think this happens due to changes to AutoField in Django 4.1. I was able to solve this issue simply by deleting existing migrations and regenerating them.

I see there is already a MR doing something similar here, non destructively: #162

Have you been able to get it work on production envoirnment

Collederas commented 2 years ago

I think this happens due to changes to AutoField in Django 4.1. I was able to solve this issue simply by deleting existing migrations and regenerating them. I see there is already a MR doing something similar here, non destructively: #162

Have you been able to get it work on production envoirnment

No, I have cloned the package as a Django app and rerun migrations within my project.

Collederas commented 2 years ago

I can confirm that this release of Django fixes the problem for my project.

https://docs.djangoproject.com/en/4.1/releases/4.1.1/

nezhar commented 2 years ago

I was not able to reproduce this on SnyPy with Django 4.1.0. Thanks @Collederas for confirming that it work with 4.1.1

The release notes also mention that some fixes where applied related to the AutoField.

Fixed a regression in Django 4.1 that caused an incorrect migration when adding AutoField, BigAutoField, or SmallAutoField on PostgreSQL ([#33919](https://code.djangoproject.com/ticket/33919)).

Fixed a regression in Django 4.1 that caused a migration crash on PostgreSQL when altering AutoField, BigAutoField, or SmallAutoField to OneToOneField ([#33932](https://code.djangoproject.com/ticket/33932)).
cristianrat commented 2 years ago

I use django 4.1.1 and latest version of this package, 1.3, still getting the error

shubh010 commented 2 years ago

Still getting the same error with the latest version of djago and the package.

nezhar commented 2 years ago

@cristianrat @shubh010 which database backend and version are you using?

cristianrat commented 2 years ago

@nezhar postgres 14

shubh010 commented 2 years ago

@cristianrat @shubh010 which database backend and version are you using?

postgres

shubh010 commented 2 years ago

@nezhar postgres 14

I have cloned the package as a Django app and removed id field from the model and then ran migrations again. Now it works for me.

Collederas commented 2 years ago

I don't think there is the need to remove the id field, re-running migrations should work fine under Django 4.1.1. But make sure to unapply the ones generated before updating it.

cristianrat commented 2 years ago

I don't think there is the need to remove the id field, re-running migrations should work fine under Django 4.1.1. But make sure to unapply the ones generated before updating it.

should, but doesn't I unapplied migration for this app and re-applied it result is the same, it doesn't work

shubh010 commented 2 years ago

I don't think there is the need to remove the id field, re-running migrations should work fine under Django 4.1.1. But make sure to unapply the ones generated before updating it.

should, but doesn't I unapplied migration for this app and re-applied it result is the same, it doesn't work

I have removed the id field from migration and now it works fine for me.

cristianrat commented 2 years ago

@shubh010 really the only way?

cristianrat commented 2 years ago

no fix for this?

cristianrat commented 2 years ago

I fixed this on my db by setting auto increment (not sure if best solution, but will have to do until a real fix is implemented)

anx-mfischer commented 1 year ago

We believe that the best way forward is to create a fixture of the existing data as a backup if thats needed then make a python manage.py migrate django-rest-passwordreset zero after that and migrate again and import the fixture.

The django fix for 4.1 explains it a bit better: https://code.djangoproject.com/ticket/33919

cristianfavaro commented 1 year ago

Updating Django to 4.1.1 also worked for me. django_rest_passwordreset==1.3 djangorestframework==3.13