Warm tip: This article is reproduced from serverfault.com, please click

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

发布于 2020-07-28 14:09:23

I am working on a codebase using Django 1.9, I am busy getting everything ready to upgrade to 1.10.

I have run into an issue after migrating from python social auth to python social auth app django. I have used the steps found here

After updating my settings and url files, I ran into the below error. Does anyone know how I can get around this?

Running migrations:
  Rendering model states... DONE
  Applying social_django.0006_partial... OK
  Applying social_django.0007_code_timestamp... OK
  Applying social_django.0008_partial_timestamp... OK
  Applying social_django.0009_auto_20191118_0520...Traceback (most recent call last):
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
psycopg2.IntegrityError: column "modified" contains null values


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

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 200, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/db/migrations/executor.py", line 92, in migrate
    self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/db/migrations/migration.py", line 123, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 62, in database_forwards
    field,
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 396, in add_field
    self.execute(sql, params)
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 110, in execute
    cursor.execute(sql, params)
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/brendan/venvs/social/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: column "modified" contains null values
Questioner
Brendan
Viewed
0
AzyCrw4282 2020-08-01 00:09:17

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