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

Migration broken from 0.2.19 (and older) #28

Closed
nijel opened this issue Feb 1, 2017 · 13 comments
Closed

Migration broken from 0.2.19 (and older) #28

nijel opened this issue Feb 1, 2017 · 13 comments

Comments

@nijel
Copy link
Member

nijel commented Feb 1, 2017

This is followup for #16.

With #25 the migration from 0.2.20 and 0.2.21 is working fine, however users upgrading from 0.2.19 and older will still end up with error.

It can end up with error described in #16:

KeyError: u"Migration social_django.0002_add_related_name dependencies reference nonexistent parent node (u'social_django', u'0001_initial')"

Or it can pop up as error while validating relations (see WeblateOrg/weblate#1344):

ValueError: The field accounts.VerifiedEmail.social was declared with a lazy reference to 'social_django.usersocialauth', but app 'social_django' isn't installed.

The problem is that Django does not see the old migrations as they are just half applied (due to missing social_auth ones):

manage.py showmigrations
...
social_django
 [ ] 0005_auto_20160727_2333 (1 squashed migrations)
 [ ] 0006_partial
...

This is what is stored in the database:

id app name applied
70 default 0001_initial 2017-02-01 15:03:35.625824
112 default 0002_add_related_name 2017-02-01 15:03:41.684870
113 default 0003_alter_email_max_length 2017-02-01 15:03:41.739056
114 default 0004_auto_20160423_0400 2017-02-01 15:03:41.877357
@nijel
Copy link
Member Author

nijel commented Feb 1, 2017

The workaround that works is to upgrade to 0.2.21 first and then to social_django.

@yohanboniface
Copy link
Contributor

yohanboniface commented Feb 2, 2017

More or less same issue here, when trying to migrate from python-social-auth==python-social-auth==0.2.14 to the new system.

Traceback (most recent call last):
  File "/home/umap/.virtualenvs/umap2/bin/umap", line 9, in <module>
    load_entry_point('umap==0.8.0.rc.13', 'console_scripts', 'umap')()
  File "/home/umap/.virtualenvs/umap2/lib/python3.4/site-packages/umap/bin/__init__.py", line 12, in main
    management.execute_from_command_line()
  File "/home/umap/.virtualenvs/umap2/lib/python3.4/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/home/umap/.virtualenvs/umap2/lib/python3.4/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/umap/.virtualenvs/umap2/lib/python3.4/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/umap/.virtualenvs/umap2/lib/python3.4/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/home/umap/.virtualenvs/umap2/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 183, in handle
    executor.loader.project_state(),
  File "/home/umap/.virtualenvs/umap2/lib/python3.4/site-packages/django/db/migrations/loader.py", line 317, in project_state
    return self.graph.make_state(nodes=nodes, at_end=at_end, real_apps=list(self.unmigrated_apps))
  File "/home/umap/.virtualenvs/umap2/lib/python3.4/site-packages/django/db/migrations/graph.py", line 409, in make_state
    project_state = self.nodes[node].mutate_state(project_state, preserve=False)
  File "/home/umap/.virtualenvs/umap2/lib/python3.4/site-packages/django/db/migrations/migration.py", line 92, in mutate_state
    operation.state_forwards(self.app_label, new_state)
  File "/home/umap/.virtualenvs/umap2/lib/python3.4/site-packages/django/db/migrations/operations/fields.py", line 192, in state_forwards
    state.models[app_label, self.model_name_lower].fields
KeyError: ('social_django', 'usersocialauth')
django-admin showmigrations
…
social_django
 [ ] 0004_auto_20160423_0400 (2 squashed migrations)
 [ ] 0005_auto_20160727_2333 (1 squashed migrations)
 [ ] 0006_partial
…

Suggested workaround worked (switch to python-social-auth 0.2.21 first, run migration, then upgrade to new system). Thanks!

@marcperrin
Copy link

Hi,
Sorry I'm not very knowledgeable about the "migrations" stuff - do you guys have a detailed, step-by-step guide to perform this workaround once I've run the "bad" migration and got this error?
Thanks!

@omab
Copy link
Contributor

omab commented Feb 4, 2017

@nijel thanks for posting the results and the workaround, I've updated the migration guide to reflect this https://github.com/omab/python-social-auth/blob/master/MIGRATING_TO_SOCIAL.md#migrations.

@marcperrin take a look to the link above, that should help.

@omab omab closed this as completed Feb 4, 2017
@coriolinus
Copy link

I'm encountering the same isssue, and the steps listed in the migrations guide do not help:

$ pip list --format=columns | grep social
python-social-auth        0.2.21
rest-social-auth          0.5.0
social-auth-app-django    1.1.0
social-auth-core          1.2.0
$ ./manage.py showmigrations social_django
social_django
 [ ] 0005_auto_20160727_2333 (1 squashed migrations)
 [ ] 0006_partial
$ ./manage.py migrate social_django
Operations to perform:
  Apply all migrations: social_django
Running migrations:
  Applying social_django.0005_auto_20160727_2333...Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/mnt/d/Users/coriolinus/Documents/Toptal/cardamom/.venv_wsl/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/mnt/d/Users/coriolinus/Documents/Toptal/cardamom/.venv_wsl/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/mnt/d/Users/coriolinus/Documents/Toptal/cardamom/.venv_wsl/lib/python3.5/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/mnt/d/Users/coriolinus/Documents/Toptal/cardamom/.venv_wsl/lib/python3.5/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/mnt/d/Users/coriolinus/Documents/Toptal/cardamom/.venv_wsl/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/mnt/d/Users/coriolinus/Documents/Toptal/cardamom/.venv_wsl/lib/python3.5/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/mnt/d/Users/coriolinus/Documents/Toptal/cardamom/.venv_wsl/lib/python3.5/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/mnt/d/Users/coriolinus/Documents/Toptal/cardamom/.venv_wsl/lib/python3.5/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/mnt/d/Users/coriolinus/Documents/Toptal/cardamom/.venv_wsl/lib/python3.5/site-packages/django/db/migrations/migration.py", line 119, in apply
    operation.state_forwards(self.app_label, project_state)
  File "/mnt/d/Users/coriolinus/Documents/Toptal/cardamom/.venv_wsl/lib/python3.5/site-packages/django/db/migrations/operations/models.py", line 521, in state_forwards
    model_state = state.models[app_label, self.name_lower]
KeyError: ('social_django', 'association')

@michi88
Copy link

michi88 commented Mar 15, 2017

I found that I had to uninstall python-social-auth and rm -rf site-packages/social because the uninstall leaves a migration file that conflicts. After that installing 0.2.21 and running the migrations worked for me.

@lukeaus
Copy link

lukeaus commented Apr 6, 2017

I had a tricky time migrating, however I managed to overcome it using the following method to upgrade from python-social-auth v 0.2.19

  1. upgrade to python-social-auth v 0.2.21
    pip install -U "python-social-auth==0.2.21"

  2. run python migrate social_auth
    Then your django_migrations table will look like this

default     | 0001_initial
default     | 0002_add_related_name
default     | 0003_alter_email_max_length
default     | 0004_auto_20160423_0400
social_auth | 0005_auto_20160727_2333
social_auth | 0001_initial
social_auth | 0003_alter_email_max_length
social_auth | 0004_auto_20160423_0400
social_auth | 0002_add_related_name
  1. Uninstall python-social-auth
    pip uninstall "python-social-auth==0.2.21"

  2. Run pip install "social-auth-app-django>=1.0.0"
    Use version >= 1.0.0 as I had some issues with v 0.0.1 - django was giving me a warning

Your models have changes that are not yet reflected in a migration, and so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
  1. Update your project settings and imports under heading 'Settings' here https://github.com/omab/python-social-auth/blob/master/MIGRATING_TO_SOCIAL.md#migrations

  2. Run all migrations
    python manage.py migrate

Now it should be working with all migrations applied.

@ghost
Copy link

ghost commented Apr 15, 2017

Any method for upgrade from django_social_auth==0.7.28 to social_django?
Operations to perform: Apply all migrations: social_django Running migrations: Applying social_django.0001_initial...Traceback (most recent call last): ... File "/home/kuein/Projects/TogetherNetwork-Community/venv/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 326, in execute return Database.Cursor.execute(self, query) django.db.utils.OperationalError: table "social_auth_association" already exists

@rlfrahm
Copy link

rlfrahm commented Apr 17, 2017

@coriolinus I had that same issue after hammering (incorrectly) past the issue described in this comment: #22 (comment)

Doing the following db stuff got me past that issue.

$ update django_migrations set app='social_django' where app='default';

Ref: #22 (comment)

Then I encountered your error @Kuein and did the following:

$ python manage.py migrate social_django 0001 --fake

and then finished the migrations for social_django:

$ python manage.py migrate social_django

Then and appeared.. and everything works!

@imju
Copy link

imju commented Sep 15, 2017

One Caution
@rlfrahm the solution should not include this line if you are using social-apps-django (1.2.0)

$ update django_migrations set app='social_django' where app='default';

The migration checks both 'default' and 'social_django' in the migrations. If you update this, then you will get 'NodeNotFoundError' in runserver.

@chernov1985
Copy link

None of these methods worked for me when upgrading from Django 1.9 to 1.11: when trying to make manage.py migrate, I got a KeyError: ('social_django', u'association').
That's what helped:

  1. I dumped and then removed all four social_* tables from DB (only one of them - social_auth_usersocialauth - had some entries in it)
  2. I made pip uninstall for all apps with 'social' in their name
  3. pip install social-auth-app-django
  4. DELETE FROM django_migrations WHERE app='default'; (there were 4 such rows)
  5. python manage.py migrate
  6. I returned all dumped rows back to social_auth_usersocialauth. Lucky I am, its structure didn't change.
    Not it looks as working app!

@marcperrin
Copy link

marcperrin commented Jul 18, 2018 via email

@CosmoRied
Copy link

CosmoRied commented Feb 7, 2022

Try apply the migrations backwards! -

First you need to run update django_migrations set app = "social_django" where app = "default";

python manage.py migrate social_django --fake

There is an error. So now run...

python manage.py migrate social_django zero

Then finally run

python manage.py migrate social_django. Everything works. Then run whatever migration you need...

eg.


sudo heroku run python manage.py migrate social_django zero
 ›   Warning: heroku update available from 7.59.1 to 7.59.2.
Running python manage.py migrate social_django zero on ⬢ *************** up, run.2009 (Free)
/app/.heroku/python/lib/python3.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
  """)
Operations to perform:
  Unapply all migrations: social_django
Running migrations:
  Rendering model states... DONE
  Unapplying social_django.0010_uid_db_index... OK
  Unapplying social_django.0009_auto_20191118_0520... OK
  Unapplying social_django.0008_partial_timestamp... OK
  Unapplying social_django.0007_code_timestamp... OK
  Unapplying social_django.0006_partial... OK
  Unapplying social_django.0005_auto_20160727_2333... OK
  Unapplying social_django.0004_auto_20160423_0400... OK
  Unapplying social_django.0003_alter_email_max_length... OK
  Unapplying social_django.0002_add_related_name... OK
  Unapplying social_django.0001_initial...Traceback (most recent call last):

Then some error about the wrong number of constraints in the initial migration:

ValueError: Found wrong number (2) of constraints for social_auth_nonce(server_url, timestamp, salt)

Then when I tried python manage.py migrate...

  Applying social_django.0002_add_related_name... OK
  Applying social_django.0003_alter_email_max_length... OK
  Applying social_django.0004_auto_20160423_0400... OK
  Applying social_django.0005_auto_20160727_2333... OK
  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... OK
  Applying social_django.0010_uid_db_index... OK

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

No branches or pull requests