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.
* 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>
* status: new => closed
* resolution: => needsinfo
--
Ticket URL: <https://code.djangoproject.com/ticket/26429#comment:2>
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>
* status: closed => new
* resolution: needsinfo =>
--
Ticket URL: <https://code.djangoproject.com/ticket/26429#comment:4>
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>
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>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/26429#comment:7>
* owner: nobody => rtpg
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/26429#comment:8>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/6485 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/26429#comment:9>
* needs_better_patch: 0 => 1
Comment:
Tests need to be fixed on the PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/26429#comment:10>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/26429#comment:11>
* 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>