[Django] #22720: Migrating a model with 'order_with_respect_to' tries to create the '_order' colum twice.

10 views
Skip to first unread message

Django

unread,
May 28, 2014, 2:34:39 PM5/28/14
to django-...@googlegroups.com
#22720: Migrating a model with 'order_with_respect_to' tries to create the '_order'
colum twice.
---------------------------------+--------------------
Reporter: valberg | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------
Having the following models:

{{{
class Book(models.Model):
title = models.CharField(max_length=100, db_index=True)


class Comment(models.Model):
comment = models.TextField()
book = models.ForeignKey('testapp.Book')

class Meta:
order_with_respect_to = 'book'
}}}


Creating migrations works fine:

{{{
$ ./manage.py makemigrations testapp
Migrations for 'testapp':
0001_initial.py:
- Create model Book
- Create model Comment

}}}

Running them is another matter:

{{{
$ ./manage.py migrate
Operations to perform:
Synchronize unmigrated apps: contenttypes, auth, sessions, admin
Apply all migrations: testapp
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying testapp.0001_initial...Traceback (most recent call last):
File "/home/valberg/Code/projects/django/django/db/backends/utils.py",
line 63, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: column "_order" specified more than once


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File
"/home/valberg/Code/projects/django/django/core/management/__init__.py",
line 384, in execute_from_command_line
utility.execute()
File
"/home/valberg/Code/projects/django/django/core/management/__init__.py",
line 376, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/valberg/Code/projects/django/django/core/management/base.py",
line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/valberg/Code/projects/django/django/core/management/base.py",
line 337, in execute
output = self.handle(*args, **options)
File
"/home/valberg/Code/projects/django/django/core/management/commands/migrate.py",
line 146, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File
"/home/valberg/Code/projects/django/django/db/migrations/executor.py",
line 62, in migrate
self.apply_migration(migration, fake=fake)
File
"/home/valberg/Code/projects/django/django/db/migrations/executor.py",
line 96, in apply_migration
migration.apply(project_state, schema_editor)
File
"/home/valberg/Code/projects/django/django/db/migrations/migration.py",
line 107, in apply
operation.database_forwards(self.app_label, schema_editor,
project_state, new_state)
File
"/home/valberg/Code/projects/django/django/db/migrations/operations/models.py",
line 30, in database_forwards
schema_editor.create_model(model)
File "/home/valberg/Code/projects/django/django/db/backends/schema.py",
line 267, in create_model
self.execute(sql, params)
File "/home/valberg/Code/projects/django/django/db/backends/schema.py",
line 98, in execute
cursor.execute(sql, params)
File "/home/valberg/Code/projects/django/django/db/backends/utils.py",
line 78, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/valberg/Code/projects/django/django/db/backends/utils.py",
line 63, in execute
return self.cursor.execute(sql, params)
File "/home/valberg/Code/projects/django/django/db/utils.py", line 94, in
__exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/valberg/Code/projects/django/django/utils/six.py", line 549,
in reraise
raise value.with_traceback(tb)
File "/home/valberg/Code/projects/django/django/db/backends/utils.py",
line 63, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column "_order" specified more than once
}}}


Apparently the column '_order' gets inserted twice in the SQL statement.

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

Django

unread,
May 28, 2014, 2:39:02 PM5/28/14
to django-...@googlegroups.com
#22720: Migrating a model with 'order_with_respect_to' tries to create the '_order'
colum twice.
---------------------------------+--------------------------------------

Reporter: valberg | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Release blocker | 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 valberg):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

This is migration file that gets created by makemigrations:

{{{
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='Book',
fields=[
('id', models.AutoField(verbose_name='ID',
serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=100,
db_index=True)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Comment',
fields=[
('id', models.AutoField(verbose_name='ID',
serialize=False, auto_created=True, primary_key=True)),
('comment', models.TextField()),
('book', models.ForeignKey(to_field='id',
to='testapp.Book')),
('_order', models.OrderWrt()),
],
options={
'order_with_respect_to': 'book',
},
bases=(models.Model,),
),
]
}}}

So might be something with the migration picking up on the '_order' field
and including it itself, and therefore it gets inserted twice in the SQL?

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

Django

unread,
May 28, 2014, 2:43:19 PM5/28/14
to django-...@googlegroups.com
#22720: Migrating a model with 'order_with_respect_to' tries to create the '_order'
colum twice.
---------------------------------+------------------------------------

Reporter: valberg | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
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
---------------------------------+------------------------------------
Changes (by charettes):

* stage: Unreviewed => Accepted


Comment:

Managed to reproduce on SQLite3. Might be related to #22720.

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

Django

unread,
May 28, 2014, 2:45:33 PM5/28/14
to django-...@googlegroups.com
#22720: Migrating a model with 'order_with_respect_to' tries to create the '_order'
colum twice.
---------------------------------+------------------------------------

Reporter: valberg | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
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
---------------------------------+------------------------------------

Comment (by valberg):

Removing

{{{
('_order', models.OrderWrt()),
}}}

makes the migrate command succeed, and there is a _order column on the
database table.

It might be a simple "do not include OrderWrt in the makemigrations
command".

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

Django

unread,
May 28, 2014, 3:28:54 PM5/28/14
to django-...@googlegroups.com
#22720: Migrating a model with 'order_with_respect_to' tries to create the '_order'
colum twice.
---------------------------------+------------------------------------
Reporter: valberg | Owner: valberg
Type: Bug | Status: assigned
Component: Migrations | Version: master

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
---------------------------------+------------------------------------
Changes (by valberg):

* owner: nobody => valberg
* status: new => assigned


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

Django

unread,
May 28, 2014, 6:18:27 PM5/28/14
to django-...@googlegroups.com
#22720: Migrating a model with 'order_with_respect_to' tries to create the '_order'
colum twice.
---------------------------------+------------------------------------
Reporter: valberg | Owner: valberg
Type: Bug | Status: assigned
Component: Migrations | Version: master

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
---------------------------------+------------------------------------

Comment (by valberg):

Removing:

{{{


options={
'order_with_respect_to': 'book',
},
}}}

from the migration (but keeping `('_order', models.OrderWrt()),`) also
makes the migration work just fine.

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

Django

unread,
May 28, 2014, 6:43:15 PM5/28/14
to django-...@googlegroups.com
#22720: Migrating a model with 'order_with_respect_to' tries to create the '_order'
colum twice.
---------------------------------+------------------------------------
Reporter: valberg | Owner: valberg
Type: Bug | Status: assigned
Component: Migrations | Version: master

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
---------------------------------+------------------------------------

Comment (by andrewgodwin):

The correct approach here is to remove the _order field from the generated
migration's list of fields. I'm currently rewriting the autodetector so I
can do this if you want, valberg.

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

Django

unread,
May 28, 2014, 7:02:42 PM5/28/14
to django-...@googlegroups.com
#22720: Migrating a model with 'order_with_respect_to' tries to create the '_order'
colum twice.
---------------------------------+------------------------------------
Reporter: valberg | Owner: valberg
Type: Bug | Status: assigned
Component: Migrations | Version: master

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

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

* has_patch: 0 => 1


Comment:

I've made the following commit after discussion with andrewgodwin on irc:

https://github.com/django/django/pull/2734

--
Ticket URL: <https://code.djangoproject.com/ticket/22720#comment:7>

Django

unread,
May 28, 2014, 8:12:24 PM5/28/14
to django-...@googlegroups.com
#22720: Migrating a model with 'order_with_respect_to' tries to create the '_order'
colum twice.
---------------------------------+------------------------------------
Reporter: valberg | Owner: valberg
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Release blocker | Resolution: fixed

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

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

Comment (by Andrew Godwin <andrew@…>):

In [changeset:"61185bba72dbb13e4f5f233f6be790957a57914c"]:
{{{
#!CommitTicketReference repository=""
revision="61185bba72dbb13e4f5f233f6be790957a57914c"
Merge pull request #2734 from valberg/double_order_trouble

Fixed #22720 -- Migrations attempt to create _order twice.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22720#comment:9>

Django

unread,
May 28, 2014, 8:12:25 PM5/28/14
to django-...@googlegroups.com
#22720: Migrating a model with 'order_with_respect_to' tries to create the '_order'
colum twice.
---------------------------------+------------------------------------
Reporter: valberg | Owner: valberg
Type: Bug | Status: closed
Component: Migrations | Version: master

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

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Víðir Valberg Guðmundsson <valberg@…>):

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


Comment:

In [changeset:"6cfa2fae3963c11e4c8ad180decba2928736dba0"]:
{{{
#!CommitTicketReference repository=""
revision="6cfa2fae3963c11e4c8ad180decba2928736dba0"


Fixed #22720 -- Migrations attempt to create _order twice.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22720#comment:8>

Django

unread,
May 29, 2014, 7:54:33 AM5/29/14
to django-...@googlegroups.com
#22720: Migrating a model with 'order_with_respect_to' tries to create the '_order'
colum twice.
---------------------------------+------------------------------------
Reporter: valberg | Owner: valberg
Type: Bug | Status: closed
Component: Migrations | Version: master

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

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

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

In [changeset:"0ee27d5b62a76781f5d78fc3f506dca624941062"]:
{{{
#!CommitTicketReference repository=""
revision="0ee27d5b62a76781f5d78fc3f506dca624941062"
[1.7.x] Fixed #22720 -- Migrations attempt to create _order twice.

Backport of 6cfa2fae39 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22720#comment:10>

Reply all
Reply to author
Forward
0 new messages