Skip to content

Instantly share code, notes, and snippets.

@aaronlelevier
Last active May 17, 2016 22:31
Show Gist options
  • Select an option

  • Save aaronlelevier/867a69679549e49f2986bcfd3ddc300b to your computer and use it in GitHub Desktop.

Select an option

Save aaronlelevier/867a69679549e49f2986bcfd3ddc300b to your computer and use it in GitHub Desktop.

Got this error when changing a ManyToMany 'through' table name

(django19)[~/Documents/bsrs/bsrs-django/bigsky]$ ./manage.py migrate
Operations to perform:
  Apply all migrations: accounting, category, flatpages, contenttypes, admin, sites, person, ticket, auth, work_request, dtd, third_party, work_order, location, contact, generic, setting, translation, sessions, utils
Running migrations:
  No migrations to apply.
  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.
The following content types are stale and need to be deleted:

    setting | manytomanysetting

Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.

    Type 'yes' to continue, or 'no' to cancel: yes
(django19)[~/Documents/bsrs/bsrs-django/bigsky]$ ./manage.py makemigrations
Did you rename the setting.ManyToManySetting model to ThroughSetting? [y/N] y
Migrations for 'setting':
  0005_auto_20160517_2227.py:
    - Rename model ManyToManySetting to ThroughSetting
    - Alter field settings on combinedsetting
(django19)[~/Documents/bsrs/bsrs-django/bigsky]$ ./manage.py migrate
Operations to perform:
  Apply all migrations: ticket, category, flatpages, auth, admin, generic, work_order, dtd, sites, utils, setting, translation, contact, contenttypes, third_party, sessions, location, accounting, person, work_request
Running migrations:
  Rendering model states... DONE
  Applying setting.0005_auto_20160517_2227...Traceback (most recent call last):
  File "./manage.py", line 11, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/alelevier/.virtualenvs/django19/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/Users/alelevier/.virtualenvs/django19/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/alelevier/.virtualenvs/django19/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/alelevier/.virtualenvs/django19/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/Users/alelevier/.virtualenvs/django19/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 200, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/Users/alelevier/.virtualenvs/django19/lib/python3.4/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 "/Users/alelevier/.virtualenvs/django19/lib/python3.4/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 "/Users/alelevier/.virtualenvs/django19/lib/python3.4/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Users/alelevier/.virtualenvs/django19/lib/python3.4/site-packages/django/db/migrations/migration.py", line 123, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Users/alelevier/.virtualenvs/django19/lib/python3.4/site-packages/django/db/migrations/operations/fields.py", line 201, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/Users/alelevier/.virtualenvs/django19/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 465, in alter_field
    old_field.remote_field.through._meta.auto_created and
AttributeError: 'str' object has no attribute '_meta'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment