Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#25922 closed Bug (fixed)

migrate --fake-initial fails to handle ManyToManyFields created by AddField

Reported by: tkhyn Owned by: Tim Graham
Component: Migrations Version: 1.9
Severity: Release blocker Keywords: migrate, syncdb, migrations
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello,

I've run into an issue with Django 1.9's new migrate --run-syncdb command, which is supposed to replace syncdb. It does not seem to be related to #25884.

Basically, the workflow syncdb => makemigrations => migrate --fake-initial is broken when ManyToManyFields are used in models. Using any other field (even FKs) work fine.

I found out that when running migrate --fake-initial, MigrationExecutor.detect_soft_applied could not find a matching column for the M2M field in the existing table, and therefore considers that the initial migration has not been implicitly applied. My understanding is that migrate --run-syncdb failed to create that in the first place.

I have set up a minimal project to expose the issue:

My use case ? django-gm2m's test suite needs to initialize individual apps one by one and sync the db before each TestCase (and then run migration tests from that state).

Thanks in advance for looking into this, and thanks already for all the work put in Django so far!

Change History (7)

comment:1 Changed 4 years ago by Tim Graham

Severity: NormalRelease blocker
Summary: migrate --run-syncdb with ManyToManyFields on 1.9migrate --fake-initial fails to handle ManyToManyFields created by AddField
Triage Stage: UnreviewedAccepted

comment:2 Changed 4 years ago by Tim Graham

Owner: changed from nobody to Tim Graham
Status: newassigned

comment:3 Changed 4 years ago by Tim Graham

Has patch: set

comment:4 Changed 4 years ago by Simon Charette

Triage Stage: AcceptedReady for checkin

comment:5 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In fa9ce4e9:

Fixed #25922 -- Fixed migrate --fake-initial detection of many-to-many tables.

comment:6 Changed 4 years ago by Tim Graham <timograham@…>

In a80fb8a:

[1.9.x] Fixed #25922 -- Fixed migrate --fake-initial detection of many-to-many tables.

Backport of fa9ce4e9a691e4f8c8b093784bac752e488dc60b from master

comment:7 Changed 4 years ago by tkhyn

Thanks a lot Tim, everything seems to work perfectly now.

Note: See TracTickets for help on using tickets.
Back to Top