[Django]-Error: psycopg2.IntegrityError: column "modified" contains null values in social auth module?

2👍

This usually happens when you upgrade the module and the newer module’s models have new constraints, in your case

column "modified" contains null values

One way is to delete just the instance that are causing the error. For this, go to the migrations folder and delete manually files that have 0009_auto_20191118_0520 type of name, you can delete, probably all, but 0001_initial.py file. After that run
python ./manage.py make migrations social_django, it should update your database.

You can also consider clearing the migration history for the social_django app, with the cmd

$ python manage.py migrate --fake social_django zero

Follow the tutorial here on how you can do that.

Edit:
You can overcome this by downgrading to a lower version of social auth app django. The latest version was to get to on Django 1.9 was social-auth-app-django==3.1.0

0👍

I was able to overcome this by downgrading to a lower version of social auth app django. The latest version I was able to get to on Django 1.9 was social-auth-app-django==3.1.0

0👍

I hit the exact same issue. (pip install "python-social-auth==0.2.21" -> set social.apps.django_app.default in INSTALLED_APPS -> python manage.py migrate -> pip install python-social-auth[django] -> set social_django in INSTALLED_APPS -> python manage.py migrate = column "modified" contains null values).

At first I thought this was a conflict between the model and the changes in the migrations file. E.g. from here:

django.db.utils.IntegrityError: column "venue_city" contains null values

Looks like you added null=True after created migration file

However, that doesn’t look right because /usr/local/lib/python2.7/site-packages/social_django/models.py does not include null=True:

    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)

Instead, I suspect the issue is the default value to update existing rows when creating the column is null which immediately conflicts. This is discussed here:

Django Migrations Add Field with Default as Function of Model

I got past this error by adding null=True to the modified field in /usr/local/lib/python2.7/site-packages/social_django/migrations/0009_auto_20191118_0520.py (or wherever social_django is installed) and re-running migrations.

        migrations.AddField(
            model_name='usersocialauth',
            name='created',
            field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name='usersocialauth',
            name='modified',
-           field=models.DateTimeField(auto_now=True),
+           field=models.DateTimeField(auto_now=True, null=True),
        ),

A better way might be to set default=django.utils.timezone.now as is already done for the created field.

Leave a comment