Opened 12 years ago
Closed 12 years ago
#21497 closed Bug (fixed)
TypeError when running database migrate command
| Reported by: | jbohman | Owned by: | |
|---|---|---|---|
| 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:1 by , 12 years ago
| Has patch: | set |
|---|
comment:2 by , 12 years ago
| Needs tests: | set |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
Could you provide a regression testcase in the test migration app?
comment:3 by , 12 years ago
Added a regression testcase to the test schema app, it seemed more appropriate. The pull request is updated.
comment:4 by , 12 years ago
| Owner: | set to |
|---|---|
| Resolution: | → fixed |
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
PR: https://github.com/django/django/pull/1967