Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem porting from django-social-auth to python-social-auth #682

Closed
laginha opened this issue Jul 15, 2015 · 2 comments
Closed

Problem porting from django-social-auth to python-social-auth #682

laginha opened this issue Jul 15, 2015 · 2 comments

Comments

@laginha
Copy link

laginha commented Jul 15, 2015

I'm migrating to django 1.8 and I took this change to port from django-social-auth to python-social-auth.

However I'm having problems with python-social-auth's migrations. It seems its initial migration does not match with the latest models.py in django-social-auth. The difference is, python-social-auth adds a new model Code. Which means:

  • if I fake the initial migration, migrating 0003 will not work

    django.db.utils.ProgrammingError: relation "social_auth_code" does not exist`
    
  • if I don't fake the initial migration, I immediately get an error

    django.db.utils.ProgrammingError: relation "social_auth_association" already exists`
    

Any suggestion on how to solve this problem?
Thanks

@laginha
Copy link
Author

laginha commented Jul 16, 2015

I solved the problem.

While in django 1.6:

  1. pip install python-social-auth
  2. remove "social_auth" from the INSTALLED_APPS.
  3. add "social.apps.django_app.default" to the INSTALLED_APPS.
  4. add SOUTH_MIGRATION_MODULES = { "default": "social_auth.migrations"} to settings.py.
  5. Create and empty migration to freeze the app: python manage.py schemamigration --freeze default default freeze --empty
  6. Create a migration to add the Code model: python manage.py schemamigration default --auto
  7. Apply both migrations: python manage.py migrate default

When that is done, you have django-social-auth's and python-social-auth's migrations in sync. Thus after you upgrade to django 1.7 or higher:

  1. remove from settings.py the previously added SOUTH_MIGRATION_MODULES option.
  2. remove "south" from the INSTALLED_APPS (you may also need to uninstall it)
  3. apply python-social-auth migrations:
    1. python manage.py migrate default 0001 --fake
    2. python manage.py migrate default

@dbrgn
Copy link

dbrgn commented Oct 29, 2015

I had the same problem. Apparently my database was in an inconsistent state, probably due to switching to Django 1.7 and PSA at the same time.

I ended up fixing it in the database directly, by using the output from python manage.py sqlmigrate default 0001 and comparing it with the state of the live database.

In my case these changes were missing:

BEGIN;
CREATE TABLE "social_auth_code" ("id" serial NOT NULL PRIMARY KEY, "email" varchar(75) NOT NULL, "code" varchar(32) NOT NULL, "verified" boolean NOT NULL);
ALTER TABLE "social_auth_code" ADD CONSTRAINT "social_auth_code_email_75f27066d057e3b6_uniq" UNIQUE ("email", "code");
ALTER TABLE "social_auth_nonce" ADD CONSTRAINT "social_auth_nonce_server_url_36601f978463b4_uniq" UNIQUE ("server_url", "timestamp", "salt");
CREATE INDEX "social_auth_code_c1336794" ON "social_auth_code" ("code");
CREATE INDEX "social_auth_code_code_32d820bdeaa954bc_like" ON "social_auth_code" ("code" varchar_pattern_ops);
CREATE INDEX "social_auth_usersocialauth_e8701ad4" ON "social_auth_usersocialauth" ("user_id");
COMMIT;

After that, the migrations would apply cleanly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants