#26384: Django 1.9 regression in migrations due to lazy model operations
refactor
---------------------------------+------------------------------------
Reporter: brian | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Description changed by akki:
Old description:
> With open source project called spud.
>
> Generates Exception:
>
> {{{
> FieldDoesNotExist: album has no field named u'album_id'
> }}}
>
> This field was removed. However in the migration that is being run when
> it fails, it did exist. So as a result, I suspect this isn't #26180.
>
> The migration in question attempts to rename the album_id field to id.
>
> Works fine with Python 3.4 or Django < =1.8
>
> Stack Trace:
>
> {{{
> /usr/lib/python2.7/dist-packages/pytest_django/fixtures.py:54: in
> _django_db_setup
> interactive=False)
> /tmp/deleteme/local/lib/python2.7/site-
> packages/django/test/runner.py:726: in setup_databases
> serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE",
> True),
> /tmp/deleteme/local/lib/python2.7/site-
> packages/django/db/backends/base/creation.py:70: in create_test_db
> run_syncdb=True,
> /tmp/deleteme/local/lib/python2.7/site-
> packages/django/core/management/__init__.py:119: in call_command
> return command.execute(*args, **defaults)
> /tmp/deleteme/local/lib/python2.7/site-
> packages/django/core/management/base.py:399: in execute
> output = self.handle(*args, **options)
> /tmp/deleteme/local/lib/python2.7/site-
> packages/django/core/management/commands/migrate.py:200: in handle
> executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
> /tmp/deleteme/local/lib/python2.7/site-
> packages/django/db/migrations/executor.py:92: in migrate
> self._migrate_all_forwards(plan, full_plan, fake=fake,
> fake_initial=fake_initial)
> /tmp/deleteme/local/lib/python2.7/site-
> packages/django/db/migrations/executor.py:121: in _migrate_all_forwards
> state = self.apply_migration(state, migration, fake=fake,
> fake_initial=fake_initial)
> /tmp/deleteme/local/lib/python2.7/site-
> packages/django/db/migrations/executor.py:198: in apply_migration
> state = migration.apply(state, schema_editor)
> /tmp/deleteme/local/lib/python2.7/site-
> packages/django/db/migrations/migration.py:123: in apply
> operation.database_forwards(self.app_label, schema_editor, old_state,
> project_state)
> /tmp/deleteme/local/lib/python2.7/site-
> packages/django/db/migrations/operations/fields.py:275: in
> database_forwards
> to_model._meta.get_field(self.new_name),
> /tmp/deleteme/local/lib/python2.7/site-
> packages/django/db/backends/base/schema.py:482: in alter_field
> old_db_params, new_db_params, strict)
> /tmp/deleteme/local/lib/python2.7/site-
> packages/django/db/backends/sqlite3/schema.py:245: in _alter_field
> self._remake_table(model, alter_fields=[(old_field, new_field)])
> /tmp/deleteme/local/lib/python2.7/site-
> packages/django/db/backends/sqlite3/schema.py:181: in _remake_table
> self.create_model(temp_model)
> /tmp/deleteme/local/lib/python2.7/site-
> packages/django/db/backends/base/schema.py:250: in create_model
> to_column =
> field.remote_field.model._meta.get_field(field.remote_field.field_name).column
> }}}
>
> Actual error is in get_field() at
>
> {{{
> /tmp/deleteme/local/lib/python2.7/site-
> packages/django/db/models/options.py:582: FieldDoesNotExist
> }}}
>
> The migration that appears to be causing the problems (wish I could tell
> which step was failing):
>
> {{{
> # -*- coding: utf-8 -*-
> from __future__ import unicode_literals
>
> from django.db import models, migrations
>
> class Migration(migrations.Migration):
>
> dependencies = [
> ('spud', '0003_auto_20141217_0908'),
> ]
>
> operations = [
> migrations.AlterModelOptions(
> name='photo',
> options={'ordering': ['datetime', 'id']},
> ),
> migrations.RenameField(
> model_name='album',
> old_name='album_id',
> new_name='id',
> ),
> migrations.RenameField(
> model_name='category',
> old_name='category_id',
> new_name='id',
> ),
> migrations.RenameField(
> model_name='person',
> old_name='person_id',
> new_name='id',
> ),
> migrations.RenameField(
> model_name='photo',
> old_name='photo_id',
> new_name='id',
> ),
> migrations.RenameField(
> model_name='place',
> old_name='place_id',
> new_name='id',
> ),
> ]
> }}}
New description:
With open source project called spud.
Generates Exception:
{{{
FieldDoesNotExist: album has no field named u'album_id'
}}}
This field was removed. However in the migration that is being run when it
fails, it did exist. So as a result, I suspect this isn't #26180.
The migration in question attempts to rename the album_id field to id.
Works fine with Django < =1.8
Stack Trace:
{{{
/usr/lib/python2.7/dist-packages/pytest_django/fixtures.py:54: in
_django_db_setup
interactive=False)
/tmp/deleteme/local/lib/python2.7/site-packages/django/test/runner.py:726:
in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE",
True),
/tmp/deleteme/local/lib/python2.7/site-
packages/django/db/backends/base/creation.py:70: in create_test_db
run_syncdb=True,
/tmp/deleteme/local/lib/python2.7/site-
packages/django/core/management/__init__.py:119: in call_command
return command.execute(*args, **defaults)
/tmp/deleteme/local/lib/python2.7/site-
packages/django/core/management/base.py:399: in execute
output = self.handle(*args, **options)
/tmp/deleteme/local/lib/python2.7/site-
packages/django/core/management/commands/migrate.py:200: in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
/tmp/deleteme/local/lib/python2.7/site-
packages/django/db/migrations/executor.py:92: in migrate
self._migrate_all_forwards(plan, full_plan, fake=fake,
fake_initial=fake_initial)
/tmp/deleteme/local/lib/python2.7/site-
packages/django/db/migrations/executor.py:121: in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake,
fake_initial=fake_initial)
/tmp/deleteme/local/lib/python2.7/site-
packages/django/db/migrations/executor.py:198: in apply_migration
state = migration.apply(state, schema_editor)
/tmp/deleteme/local/lib/python2.7/site-
packages/django/db/migrations/migration.py:123: in apply
operation.database_forwards(self.app_label, schema_editor, old_state,
project_state)
/tmp/deleteme/local/lib/python2.7/site-
packages/django/db/migrations/operations/fields.py:275: in
database_forwards
to_model._meta.get_field(self.new_name),
/tmp/deleteme/local/lib/python2.7/site-
packages/django/db/backends/base/schema.py:482: in alter_field
old_db_params, new_db_params, strict)
/tmp/deleteme/local/lib/python2.7/site-
packages/django/db/backends/sqlite3/schema.py:245: in _alter_field
self._remake_table(model, alter_fields=[(old_field, new_field)])
/tmp/deleteme/local/lib/python2.7/site-
packages/django/db/backends/sqlite3/schema.py:181: in _remake_table
self.create_model(temp_model)
/tmp/deleteme/local/lib/python2.7/site-
packages/django/db/backends/base/schema.py:250: in create_model
to_column =
field.remote_field.model._meta.get_field(field.remote_field.field_name).column
}}}
Actual error is in get_field() at
{{{
/tmp/deleteme/local/lib/python2.7/site-
packages/django/db/models/options.py:582: FieldDoesNotExist
}}}
The migration that appears to be causing the problems (wish I could tell
which step was failing):
{{{
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('spud', '0003_auto_20141217_0908'),
]
operations = [
migrations.AlterModelOptions(
name='photo',
options={'ordering': ['datetime', 'id']},
),
migrations.RenameField(
model_name='album',
old_name='album_id',
new_name='id',
),
migrations.RenameField(
model_name='category',
old_name='category_id',
new_name='id',
),
migrations.RenameField(
model_name='person',
old_name='person_id',
new_name='id',
),
migrations.RenameField(
model_name='photo',
old_name='photo_id',
new_name='id',
),
migrations.RenameField(
model_name='place',
old_name='place_id',
new_name='id',
),
]
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/26384#comment:8>
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/063.bcf7776a03d7485732f10a63aeee5504%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.