Opened 11 years ago

Closed 11 years ago

#21497 closed Bug (fixed)

TypeError when running database migrate command

Reported by: jbohman Owned by: Tim Graham <timograham@…>
Component: Migrations Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The TypeError appears when the index name is too long and must be hashed to fit.

Added traceback below and will add a pull request very soon.

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File ".../lib/python3.3/site-packages/django/core/management/__init__.py", line 416, in execute_from_command_line
    utility.execute()
  File ".../lib/python3.3/site-packages/django/core/management/__init__.py", line 408, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ".../lib/python3.3/site-packages/django/core/management/base.py", line 244, in run_from_argv
    self.execute(*args, **options.__dict__)
  File ".../lib/python3.3/site-packages/django/core/management/base.py", line 291, in execute
    output = self.handle(*args, **options)
  File ".../lib/python3.3/site-packages/django/core/management/commands/migrate.py", line 124, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File ".../lib/python3.3/site-packages/django/db/migrations/executor.py", line 60, in migrate
    self.apply_migration(migration, fake=fake)
  File ".../lib/python3.3/site-packages/django/db/migrations/executor.py", line 94, in apply_migration
    migration.apply(project_state, schema_editor)
  File ".../lib/python3.3/site-packages/django/db/migrations/migration.py", line 97, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File ".../lib/python3.3/site-packages/django/db/migrations/operations/models.py", line 26, in database_forwards
    schema_editor.create_model(model)
  File ".../lib/python3.3/site-packages/django/db/backends/schema.py", line 209, in create_model
    "name": self._create_index_name(model, [field.column], suffix="_fk_%s_%s" % (to_table, to_column)),
  File ".../lib/python3.3/site-packages/django/db/backends/schema.py", line 706, in _create_index_name
    index_name = hashlib.md5(index_name).hexdigest()[:self.connection.features.max_index_name_length]
TypeError: Unicode-objects must be encoded before hashing

Change History (4)

comment:2 by Simon Charette, 11 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

Could you provide a regression testcase in the test migration app?

comment:3 by jbohman, 11 years ago

Added a regression testcase to the test schema app, it seemed more appropriate. The pull request is updated.

comment:4 by Tim Graham <timograham@…>, 11 years ago

Owner: set to Tim Graham <timograham@…>
Resolution: fixed
Status: newclosed

In 19e5cd77f0536b778b00788e34d8199835143855:

Fixed #21497 -- Forced conversion to bytes for very long index names

Note: See TracTickets for help on using tickets.
Back to Top