[Django] #23614: Altering unique_together sometimes missing deleted fields

11 views
Skip to first unread message

Django

unread,
Oct 7, 2014, 6:07:54 PM10/7/14
to django-...@googlegroups.com
#23614: Altering unique_together sometimes missing deleted fields
----------------------------+--------------------
Reporter: Naddiseo | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
Steps to reproduce:
1. Create an App `spam`
2. Create two models `spam.Eggs` and `spam.Spam`

{{{
#!python

class Eggs(models.Model):
pass


class Spam(models.Model):
class Meta:
unique_together = (
('a', 'b'),
)

a = models.ForeignKey(Eggs)
b = models.CharField(max_length=10)
}}}

3. Make migrations
4. Create an App `ham`
5. Create model `ham.Ham`

{{{
#!python
class Ham(models.Model): pass
}}}
6. Add foreignkey to `Spam.Spam`: `c = models.ForeignKey('ham.Ham')`
7. Make Migrations
8. Delete field `Spam.a`
9. Change `Spam.unique_together` to `('c', 'b')`
10. Make Migrations
11. Run migrations.

Output:

> django.db.models.fields.FieldDoesNotExist: Spam has no field named u'a'


I think this might be related to issue #23505 since that is what I was
actually trying to reproduce.

--
Ticket URL: <https://code.djangoproject.com/ticket/23614>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 7, 2014, 6:36:44 PM10/7/14
to django-...@googlegroups.com
#23614: Altering unique_together sometimes missing deleted fields
----------------------------+--------------------------------------

Reporter: Naddiseo | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by Naddiseo):

* cc: github@… (added)
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/23614#comment:1>

Django

unread,
Oct 13, 2014, 11:15:19 AM10/13/14
to django-...@googlegroups.com
#23614: Altering unique_together sometimes missing deleted fields
----------------------------+------------------------------------

Reporter: Naddiseo | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Changes (by bmispelon):

* stage: Unreviewed => Accepted


Comment:

Hi,

I can reproduce the issue (I had to use `c = models.ForeignKey('ham.Ham',
null=True)` though otherwise it asked me for a default when running
`makemigrations`).

The traceback under Python 3 provides a little bit more information:
{{{#!python
Traceback (most recent call last):
File "./django/db/models/options.py", line 404, in get_field_by_name
return self._name_map[name]
AttributeError: 'Options' object has no attribute '_name_map'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "./django/db/models/options.py", line 407, in get_field_by_name
return cache[name]
KeyError: 'a'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "./django/core/management/__init__.py", line 336, in
execute_from_command_line
utility.execute()
File "./django/core/management/__init__.py", line 328, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "./django/core/management/base.py", line 369, in run_from_argv
self.execute(*args, **cmd_options)
File "./django/core/management/base.py", line 419, in execute
output = self.handle(*args, **options)
File "./django/core/management/commands/migrate.py", line 193, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "./django/db/migrations/executor.py", line 63, in migrate
self.apply_migration(migration, fake=fake)
File "./django/db/migrations/executor.py", line 97, in apply_migration
migration.apply(project_state, schema_editor)
File "./django/db/migrations/migration.py", line 107, in apply
operation.database_forwards(self.app_label, schema_editor,
project_state, new_state)
File "./django/db/migrations/operations/fields.py", line 84, in
database_forwards
schema_editor.remove_field(from_model,
from_model._meta.get_field_by_name(self.name)[0])
File "./django/db/backends/sqlite3/schema.py", line 185, in remove_field
self._remake_table(model, delete_fields=[field])
File "./django/db/backends/sqlite3/schema.py", line 128, in
_remake_table
self.create_model(temp_model)
File "./django/db/backends/schema.py", line 253, in create_model
columns = [model._meta.get_field_by_name(field)[0].column for field in
fields]
File "./django/db/backends/schema.py", line 253, in <listcomp>
columns = [model._meta.get_field_by_name(field)[0].column for field in
fields]
File "./django/db/models/options.py", line 410, in get_field_by_name
% (self.object_name, name))
django.db.models.fields.FieldDoesNotExist: Spam has no field named 'a'
}}}

Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/23614#comment:2>

Django

unread,
Oct 27, 2014, 6:16:17 PM10/27/14
to django-...@googlegroups.com
#23614: Altering unique_together sometimes missing deleted fields
----------------------------+---------------------------------------
Reporter: Naddiseo | Owner: Markush2010
Type: Bug | Status: assigned
Component: Migrations | Version: 1.7

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+---------------------------------------
Changes (by Markush2010):

* status: new => assigned
* cc: info+coding@… (added)
* owner: nobody => Markush2010
* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/23614#comment:3>

Django

unread,
Oct 27, 2014, 8:56:33 PM10/27/14
to django-...@googlegroups.com
#23614: Altering unique_together sometimes missing deleted fields
----------------------------+---------------------------------------
Reporter: Naddiseo | Owner: Markush2010
Type: Bug | Status: assigned
Component: Migrations | Version: 1.7

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+---------------------------------------

Comment (by Markush2010):

I opened an initial pull-request:
https://github.com/django/django/pull/3430

--
Ticket URL: <https://code.djangoproject.com/ticket/23614#comment:4>

Django

unread,
Oct 29, 2014, 1:07:17 PM10/29/14
to django-...@googlegroups.com
#23614: Altering unique_together sometimes missing deleted fields
----------------------------+---------------------------------------
Reporter: Naddiseo | Owner: Markush2010
Type: Bug | Status: closed
Component: Migrations | Version: 1.7
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+---------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"5c9c1e029d139bd3d5213804af2ed9f317cd0b86"]:
{{{
#!CommitTicketReference repository=""
revision="5c9c1e029d139bd3d5213804af2ed9f317cd0b86"
Fixed #23614 -- Changed the way the migration autodetector orders
unique/index_together

Thanks to Naddiseo for the report and Tim Graham for the review
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23614#comment:5>

Django

unread,
Oct 29, 2014, 1:21:51 PM10/29/14
to django-...@googlegroups.com
#23614: Altering unique_together sometimes missing deleted fields
----------------------------+---------------------------------------
Reporter: Naddiseo | Owner: Markush2010
Type: Bug | Status: closed
Component: Migrations | Version: 1.7

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+---------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"21358e72253aac0d26af0cff2f597c1ab7bf151c"]:
{{{
#!CommitTicketReference repository=""
revision="21358e72253aac0d26af0cff2f597c1ab7bf151c"
[1.7.x] Fixed #23614 -- Changed the way the migration autodetector orders
unique/index_together

Thanks to Naddiseo for the report and Tim Graham for the review

Backport of 5c9c1e029d from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23614#comment:6>

Reply all
Reply to author
Forward
0 new messages