Opened 7 years ago

Closed 7 years ago

#28684 closed Bug (needsinfo)

Removing an index from an IntegerField causes a KeyError exception

Reported by: Daniel Valdivia Owned by: nobody
Component: Migrations Version: 1.11
Severity: Normal Keywords: migration
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

While attempting to remove a db_index from a IntegerField through a migration the following way

class Migration(migrations.Migration):

    dependencies = [
        ('chat', '0005_auto_20170518_2103'),
    ]

    operations = [
        migrations.AlterField(
            model_name='channel',
            name='participant_count',
            field=models.IntegerField(blank=True, default=0),
        ),
    ]

A KeyError: 'type' is thrown

[standard:dpc] === Starting migration
[standard:dpc] Operations to perform:
[standard:dpc]   Apply all migrations: chat
[standard:dpc] Running migrations:
[standard:dpc]   Applying chat.0006_auto_20171005_1800...
Traceback (most recent call last):
  File "./manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django_tenants/management/commands/migrate_schemas.py", line 63, in handle
    executor.run_migrations(tenants=tenants)
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django_tenants/migration_executors/standard.py", line 15, in run_migrations
    run_migrations(self.args, self.options, self.codename, schema_name)
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django_tenants/migration_executors/base.py", line 30, in run_migrations
    MigrateCommand(stdout=stdout, stderr=stderr).execute(*args, **options)
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/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 "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/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 "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django/db/migrations/migration.py", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 216, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 515, in alter_field
    old_db_params, new_db_params, strict)
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django/db/backends/postgresql/schema.py", line 112, in _alter_field
    new_db_params, strict,
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 572, in _alter_field
    index_names = self._constraint_names(model, [old_field.column], index=True, type_=Index.suffix)
  File "/Users/dvaldivia/esdev/django/pyenv/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 1003, in _constraint_names
    if type_ is not None and infodict['type'] != type_:
KeyError: 'type'

Change History (3)

comment:1 by Tim Graham, 7 years ago

Component: UncategorizedMigrations

I haven't been able to reproduce the crash. Could you provide more specific steps to reproduce it? In case it's relevant, what version of PostgreSQL are you using?

comment:2 by Simon Charette, 7 years ago

Are you also able to reproduce without using django-tenants migration tweaks?

comment:3 by Tim Graham, 7 years ago

Resolution: needsinfo
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top