#27750: TypeError when running manage.py migrate
-------------------------------------------+------------------------
Reporter: Henrique Chehad | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
Hello,
Is returning this error when I try to run ./manage.py migrate in a model:
Model:
{{{
class Cast(models.Model):
movie = models.ForeignKey("movies.Movie")
artist = models.ForeignKey("artists.Artist", db_column="actor_id")
}}}
Migration:
{{{
migrations.AlterField(
model_name='cast',
name='artist',
field=models.ForeignKey(db_column='actor_id',
on_delete=django.db.models.deletion.CASCADE, to='artists.Artist'),
),
}}}
Error:
{{{
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/site-
packages/django/core/management/__init__.py", line 353, in
execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/site-
packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/site-
packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.5/site-
packages/raven/contrib/django/management/__init__.py", line 41, in
new_execute
return original_func(self, *args, **kwargs)
File "/usr/local/lib/python3.5/site-
packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.5/site-
packages/django/core/management/commands/migrate.py", line 200, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "/usr/local/lib/python3.5/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 "/usr/local/lib/python3.5/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 "/usr/local/lib/python3.5/site-
packages/django/db/migrations/executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/local/lib/python3.5/site-
packages/django/db/migrations/migration.py", line 123, in apply
operation.database_forwards(self.app_label, schema_editor, old_state,
project_state)
File "/usr/local/lib/python3.5/site-
packages/django/db/migrations/operations/fields.py", line 201, in
database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/usr/local/lib/python3.5/site-
packages/django/db/backends/base/schema.py", line 482, in alter_field
old_db_params, new_db_params, strict)
File "/usr/local/lib/python3.5/site-
packages/django/db/backends/postgresql/schema.py", line 110, in
_alter_field
new_db_params, strict,
File "/usr/local/lib/python3.5/site-
packages/django/db/backends/base/schema.py", line 545, in _alter_field
self.execute(self._rename_field_sql(model._meta.db_table, old_field,
new_field, new_type))
File "/usr/local/lib/python3.5/site-
packages/django/db/backends/base/schema.py", line 867, in
_rename_field_sql
"old_column": self.quote_name(old_field.column),
File "/usr/local/lib/python3.5/site-
packages/django/db/backends/base/schema.py", line 113, in quote_name
return self.connection.ops.quote_name(name)
File "/usr/local/lib/python3.5/site-
packages/django/db/backends/postgresql/operations.py", line 95, in
quote_name
if name.startswith('"') and name.endswith('"'):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
}}}
The error is in the field `artist` of `Cast` model, because I added a
`print()` to discover what is the field with the error when call the
function `quote_name` and printed `actor_id`. I commented this field in
migration just to test and worked.
Detail: I didn't changed anything in this fields, it's because when I
migrated from Python 2.7.5 to Python 3.5 the verbose_name changed (removed
the u"") and asked to generate new migrations. I think it is unnecessary.
--
Ticket URL: <https://code.djangoproject.com/ticket/27750>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/057.3ca87a4335663ac887fc2b7a16a69e18%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.