django-rest-passwordreset icon indicating copy to clipboard operation
django-rest-passwordreset copied to clipboard

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

Open shubh010 opened this issue 2 years ago • 23 comments

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).

shubh010 avatar Aug 18 '22 05:08 shubh010

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

farooq-oneclout avatar Aug 19 '22 15:08 farooq-oneclout

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

Did you get a fix

shubh010 avatar Aug 25 '22 04:08 shubh010

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

farooq-oneclout avatar Aug 25 '22 05:08 farooq-oneclout

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

shubh010 avatar Aug 26 '22 06:08 shubh010

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

Collederas avatar Sep 15 '22 13:09 Collederas

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

nezhar avatar Sep 15 '22 13:09 nezhar

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

shubh010 avatar Sep 16 '22 06:09 shubh010

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 avatar Sep 20 '22 12:09 Collederas

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/

Collederas avatar Sep 20 '22 12:09 Collederas

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)).

nezhar avatar Sep 20 '22 17:09 nezhar

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

cristianrat avatar Sep 20 '22 18:09 cristianrat

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

shubh010 avatar Sep 21 '22 03:09 shubh010

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

nezhar avatar Sep 21 '22 07:09 nezhar

@nezhar postgres 14

cristianrat avatar Sep 21 '22 07:09 cristianrat

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

postgres

shubh010 avatar Sep 21 '22 08:09 shubh010

@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.

shubh010 avatar Sep 21 '22 09:09 shubh010

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.

Collederas avatar Sep 22 '22 09:09 Collederas

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

cristianrat avatar Sep 22 '22 10:09 cristianrat

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.

shubh010 avatar Sep 22 '22 11:09 shubh010

@shubh010 really the only way?

cristianrat avatar Sep 23 '22 16:09 cristianrat

no fix for this?

cristianrat avatar Oct 08 '22 06:10 cristianrat

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)

cristianrat avatar Oct 11 '22 07:10 cristianrat

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

anx-mfischer avatar Oct 14 '22 11:10 anx-mfischer

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

cristianfavaro avatar Jul 11 '23 21:07 cristianfavaro