[Django] #26429: Name clash of merge migrations after squashing

15 views
Skip to first unread message

Django

unread,
Mar 30, 2016, 6:05:06 PM3/30/16
to django-...@googlegroups.com
#26429: Name clash of merge migrations after squashing
----------------------------+----------------------------------------
Reporter: xgenadam | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Keywords: makemigrations merge clash
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+----------------------------------------
After squashing migrations, further development can result in a merge
migration with an identical name to a squashed migration.
This is old merge is still stored in the django_migrations table and the
new merge will not be applied.

The workaround is to rename the merge to something unique. However the
automatically generated names should not clash in the first place.

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

Django

unread,
Mar 31, 2016, 11:08:44 AM3/31/16
to django-...@googlegroups.com
#26429: Name clash of merge migrations after squashing
-------------------------------------+-------------------------------------

Reporter: xgenadam | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Resolution:
Keywords: makemigrations | Triage Stage:
merge clash | 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:

For clarity, could you give the specific steps that led to the clash?

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

Django

unread,
Apr 4, 2016, 8:09:54 PM4/4/16
to django-...@googlegroups.com
#26429: Name clash of merge migrations after squashing
-------------------------------------+-------------------------------------
Reporter: xgenadam | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.9
Severity: Normal | Resolution: needsinfo

Keywords: makemigrations | Triage Stage:
merge clash | 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: => needsinfo


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

Django

unread,
Apr 18, 2016, 10:47:12 PM4/18/16
to django-...@googlegroups.com
#26429: Name clash of merge migrations after squashing
-------------------------------------+-------------------------------------
Reporter: xgenadam | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.9

Severity: Normal | Resolution: needsinfo
Keywords: makemigrations | Triage Stage:
merge clash | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by rtpg):

I just ran into a similar problem, going to detail what happened:

- Over the course of development, do a merge migration. In our case, it
was the 21st migration so got named `0021_merge.py`

- Squash our migrations, deleting `0021_merge.py`

- Continue development, and through sheer luck, our next 2st migration is
also a merge commit. It gets named `0021_merge.py`

- When running migrations, because the original migration was run, this
new `0021_merge.py` commit is not run


In my case, this was the dependencies of `0021_merge.py` (the new one):

{{{
dependencies = [
('document', '0020_auto_20160413_1834'),
('document', '0019_auto_20160414_1150'),
]
}}}

Because the merge commit wasn't run, some people only had the `0020`
mainline migrations migrated, some people only had the `0019` branch
migrations run, and some people (who hadn't run `migrate` in a while) had
the following happen:

- `migrate` detects `0021_merge.py` as the leaf node
- there was record of the (old) `0021_merge.py` migration
- the system was like "oh, guess you're up to date!" and then doesn't
run either branch of the merge commit

Like the OP, I believe the simplest solution is to timestamp the merge
migrations.

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

Django

unread,
Apr 18, 2016, 10:47:50 PM4/18/16
to django-...@googlegroups.com
#26429: Name clash of merge migrations after squashing
-------------------------------------+-------------------------------------

Reporter: xgenadam | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Resolution:

Keywords: makemigrations | Triage Stage:
merge clash | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

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


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

Django

unread,
Apr 18, 2016, 11:13:20 PM4/18/16
to django-...@googlegroups.com
#26429: Name clash of merge migrations after squashing
-------------------------------------+-------------------------------------

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

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

Comment (by rtpg):

Did a bit more digging into this, I believe that the fix is changing
[(https://github.com/django/django/blob/master/django/core/management/commands/makemigrations.py#L286)],
from :

{{{
new_migration = subclass("%04i_merge" % (biggest_number + 1), app_label)
}}}

to :

{{{
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M")
new_migration = subclass("%04i_merge_%s" % (biggest_number + 1,
timestamp), app_label)
}}}


I'm not quite sure how to write tests for this, though. You could write
some models, generate migrations, squash, generate new ones and then
confirm that everything got run? But I feel like the current `squash`
migration tests also cover this, and that there isn't really much in term
of name conflict tests.

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

Django

unread,
Apr 18, 2016, 11:32:26 PM4/18/16
to django-...@googlegroups.com
#26429: Name clash of merge migrations after squashing
-------------------------------------+-------------------------------------

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

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

Old description:

> After squashing migrations, further development can result in a merge
> migration with an identical name to a squashed migration.
> This is old merge is still stored in the django_migrations table and the
> new merge will not be applied.
>
> The workaround is to rename the merge to something unique. However the
> automatically generated names should not clash in the first place.

New description:

--

Comment (by izquierdo):

The docs in
https://github.com/django/django/blob/2cd2d188516475ddf256e6267cd82c495fb5c430/django/db/migrations/autodetector.py#L1129
say that names are not guaranteed to be unique and the timestamp is just a
best effort to avoid conflicts. So I think rtpg's suggested fix works well
for merge migrations, and a test to ensure names don't conflict is not
necessary.

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

Django

unread,
Apr 19, 2016, 9:42:49 AM4/19/16
to django-...@googlegroups.com
#26429: Name clash of merge migrations after squashing
-------------------------------------+-------------------------------------

Reporter: xgenadam | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Resolution:
Keywords: makemigrations | Triage Stage: Accepted
merge clash |

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

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

* stage: Unreviewed => Accepted


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

Django

unread,
Apr 21, 2016, 8:45:41 AM4/21/16
to django-...@googlegroups.com
#26429: Name clash of merge migrations after squashing
-------------------------------------+-------------------------------------
Reporter: xgenadam | Owner: rtpg
Type: Bug | Status: assigned
Component: Migrations | Version: 1.9

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

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

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


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

Django

unread,
Apr 21, 2016, 9:35:04 AM4/21/16
to django-...@googlegroups.com
#26429: Name clash of merge migrations after squashing
-------------------------------------+-------------------------------------
Reporter: xgenadam | Owner: rtpg
Type: Bug | Status: assigned
Component: Migrations | Version: 1.9

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

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

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/6485 PR]

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

Django

unread,
Apr 21, 2016, 7:18:04 PM4/21/16
to django-...@googlegroups.com
#26429: Name clash of merge migrations after squashing
-------------------------------------+-------------------------------------
Reporter: xgenadam | Owner: rtpg
Type: Bug | Status: assigned
Component: Migrations | Version: 1.9

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

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

* needs_better_patch: 0 => 1


Comment:

Tests need to be fixed on the PR.

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

Django

unread,
May 8, 2016, 2:52:58 PM5/8/16
to django-...@googlegroups.com
#26429: Name clash of merge migrations after squashing
-------------------------------------+-------------------------------------
Reporter: xgenadam | Owner: rtpg
Type: Bug | Status: assigned
Component: Migrations | Version: 1.9

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

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

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/26429#comment:11>

Django

unread,
May 11, 2016, 8:19:47 AM5/11/16
to django-...@googlegroups.com
#26429: Name clash of merge migrations after squashing
-------------------------------------+-------------------------------------
Reporter: xgenadam | Owner: rtpg
Type: Bug | Status: closed
Component: Migrations | Version: 1.9
Severity: Normal | Resolution: fixed

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

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

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


Comment:

In [changeset:"8f6a1a15516629b30e2fa2c48d5e682f7955868c" 8f6a1a15]:
{{{
#!CommitTicketReference repository=""
revision="8f6a1a15516629b30e2fa2c48d5e682f7955868c"
Fixed #26429 -- Added a timestamp to merge migration names.

This reduces the possibility of a naming conflict, especially after
squashing migrations.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26429#comment:12>

Reply all
Reply to author
Forward
0 new messages