September 26, 2021

How to upgrade Python Social Auth

I had an old Django project running python social auth that needed to be upgraded to Django 2, python 3 and the latest version of python social auth at the time of this writing.

These are the steps I took (adapted from here:

  1. Dump the contents of social_auth_usersocialauth into a csv file

    psql -U postgres -W postgres

    \COPY social_auth_usersocialauth TO /Users/username/Documents/persons_db_.csv’ DELIMITER ,’ CSV HEADER;

  2. Delete all the old social auth tables

DROP TABLE social_auth_usersocialauth; DROP TABLE social_auth_nonce; DROP TABLE social_auth_code; DROP TABLE social_auth_association;

  1. Delete all the old migrations DELETE FROM django_migrations WHERE app=‘default’; This deleted 3 rows for me

  2. Install the new Django social or whatever it is called. Migrate as anew. python migrate

  3. Now some of the columns are in a different order and you’ll notice there are 2 new columns (created, modified). I’ll alter the table so that importing the csv file isnt an issue

ALTER TABLE social_auth_usersocialauth ALTER COLUMN created SET DEFAULT 2022-03-02 19:58:19.398458+00’;

ALTER TABLE social_auth_usersocialauth ALTER COLUMN modified SET DEFAULT 2022-03-02 19:58:19.398458+00’;

\COPY social_auth_usersocialauth(id, user_id, provider, uid, extra_data) FROM /persons_db_.csv’ DELIMITER ,’ CSV HEADER;

ALTER TABLE social_auth_usersocialauth ALTER COLUMN created DROP DEFAULT;

ALTER TABLE social_auth_usersocialauth ALTER COLUMN modified DROP DEFAULT;

All done :)


After doing this I realized that I also need to change my pkey. This is the way you can reset” a primary key when it is out of sync

SELECT setval(‘public.“social_auth_usersocialauth_id_seq”’, (SELECT MAX(id) FROM public.social_auth_usersocialauth) );

Previous post
Bowling Mania Did you know before the Real Estate Bubble, the Dotcom Bubble, the Bicycle Bubble, there was the “Bowling Bubble” of the 1960s? While
Next post
buying website online Why to avoid buying adsense or affiliate websites If you’re a beginner in the world of buying websites online, the promise of easy passive income
Share this post if you enjoyed it :)
Subscribe to my newsletter to get notified of new posts
Follow Me On Twitter