Opened 5 years ago

Closed 4 years ago

#21497 closed Bug (fixed)

TypeError when running database migrate command

Reported by: jbohman Owned by: Tim Graham <timograham@…>
Component: Migrations Version: master
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


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 "./", line 10, in <module>
  File ".../lib/python3.3/site-packages/django/core/management/", line 416, in execute_from_command_line
  File ".../lib/python3.3/site-packages/django/core/management/", line 408, in execute
  File ".../lib/python3.3/site-packages/django/core/management/", line 244, in run_from_argv
    self.execute(*args, **options.__dict__)
  File ".../lib/python3.3/site-packages/django/core/management/", line 291, in execute
    output = self.handle(*args, **options)
  File ".../lib/python3.3/site-packages/django/core/management/commands/", line 124, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File ".../lib/python3.3/site-packages/django/db/migrations/", line 60, in migrate
    self.apply_migration(migration, fake=fake)
  File ".../lib/python3.3/site-packages/django/db/migrations/", line 94, in apply_migration
    migration.apply(project_state, schema_editor)
  File ".../lib/python3.3/site-packages/django/db/migrations/", 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/", line 26, in database_forwards
  File ".../lib/python3.3/site-packages/django/db/backends/", 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/", 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 Changed 5 years ago by Simon Charette

Needs tests: set
Triage Stage: UnreviewedAccepted

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

comment:3 Changed 5 years ago by jbohman

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

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

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