[Django] #25577: Squashed migrations do not work if deletion of indexed field can't be optimized on postgresql database

10 views
Skip to first unread message

Django

unread,
Oct 20, 2015, 2:03:45 PM10/20/15
to django-...@googlegroups.com
#25577: Squashed migrations do not work if deletion of indexed field can't be
optimized on postgresql database
----------------------------+--------------------
Reporter: jbzdak | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
I have following model:

{{{
class AModel(models.Model):
indexed_field = models.CharField(max_length=200, db_index=True)
}}}

And three migrations:

1. First one creates this model
2. Second one runs a custom sql (this SQL is empty in my example, but it
could for example copy contents of ``indexed_field`` column to another
column)
3. Third one deletes indexed field from the model

If I run these three migrations separately they work.

If I squash these migrations into one they stop working with following
error:

{{{
File "/home/jb/programs/django-migrations-issue/venv/lib/python3.5/site-
packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column "indexed_field" does not exist
}}}

My guess is this error is because:

Index creation executed as a ``deferred_sql`` statement, which is executed
at the end of migration. At the end of my squashed migration there is no
``indexed_field`` column on the table, and postgresql raises error.

It works when migrations are separate because index creation is executed
at the end of migration. It works on squashed migrations without RunSQL
migration in between because field creation is entirely optimized.

I have attached example project, if you try to migrate it, it will
explode. If you remove squashed migration it will work.

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

Django

unread,
Oct 20, 2015, 2:03:56 PM10/20/15
to django-...@googlegroups.com
#25577: Squashed migrations do not work if deletion of indexed field can't be
optimized on postgresql database
------------------------+----------------------------

Reporter: jbzdak | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------+----------------------------
Changes (by jbzdak):

* Attachment "django-migrations-issue.tar.gz" added.

Django

unread,
Oct 20, 2015, 2:22:07 PM10/20/15
to django-...@googlegroups.com
#25577: Squashed migrations do not work if deletion of indexed field can't be
optimized on postgresql database
----------------------------+--------------------------------------

Reporter: jbzdak | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
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 timgraham):

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


Comment:

From a quick look, I think the underlying cause might be a duplicate of
#25530. Can you confirm?

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

Django

unread,
Oct 20, 2015, 6:27:55 PM10/20/15
to django-...@googlegroups.com
#25577: Squashed migrations do not work if deletion of indexed field can't be
optimized on postgresql database
----------------------------+--------------------------------------

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

Comment (by jbzdak):

I think that this could be the problem, but I'm not very well versed in
django internals to be 100% sure. If you go for proposed solution it will
also solve my problem.

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

Django

unread,
Oct 21, 2015, 9:22:47 AM10/21/15
to django-...@googlegroups.com
#25577: Squashed migrations do not work if deletion of indexed field can't be
optimized on postgresql database
----------------------------+--------------------------------------
Reporter: jbzdak | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Normal | Resolution: duplicate
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 timgraham):

* status: new => closed
* resolution: => duplicate


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

Reply all
Reply to author
Forward
0 new messages