#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 by , 10 years ago
| Severity: | Normal → Release blocker | 
|---|---|
| Summary: | migrate --run-syncdb with ManyToManyFields on 1.9 → migrate --fake-initial fails to handle ManyToManyFields created by AddField | 
| Triage Stage: | Unreviewed → Accepted | 
comment:2 by , 10 years ago
| Owner: | changed from to | 
|---|---|
| Status: | new → assigned | 
comment:3 by , 10 years ago
| Has patch: | set | 
|---|
comment:4 by , 10 years ago
| Triage Stage: | Accepted → Ready for checkin | 
|---|
PR