#29897: Initial migration fails when referencing a custom user model from a sequence of at least two concrete ancestor models -------------------------------------+------------------------------------- Reporter: stevenganz | Owner: nobody Type: Bug | Status: new Component: Migrations | Version: 2.1 Severity: Normal | Resolution: Keywords: "custom user model" | Triage Stage: Accepted "abstract model" "foreign key" | Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by Simon Charette):
* severity: Release blocker => Normal * stage: Unreviewed => Accepted Comment: From my local testing this has been broken since at least Django 1.11 but the `makemigrations`'s behavior changed in the current master as the optimizer got more aggressive and assumes operation to be appropriately ordered which is not the case here. Migrations generated on Django 1.11, 2.0, and 2.1 {{{ Migrations for 'core': core/migrations/0001_initial.py - Create model A - Create model B - Add field createdByUser to a - Create model User }}} Migration generated on the current master {{{ Migrations for 'core': core/migrations/0001_initial.py - Create model A - Create model B - Create model User }}} An interesting thing here is that everything works fine on the current master if `AUTH_USER_MODEL` is not set to `core.User`. Given the optimizer is completely ''swappable model'' agnostic the issue most probably lies in the auto-detector ''swappable model'' dependency resolution. To make it clear the expected operation's order here is the same as if the model wasn't swappable {{{ Migrations for 'core': core/migrations/0001_initial.py - Create model A - Create model B - Create model User - Add field createdByUser to a }}} Downgrading to non-release blocker as this is not a regression and can be easily worked around by either generating the migration without `AUTH_USER_MODEL` pointed at `core.User` (and then adjusting it) or by manually altering the migration to move the `AddField(ForeignKey(User))` operation after the `CreateModel(User)` one. -- Ticket URL: <https://code.djangoproject.com/ticket/29897#comment:2> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.5a20b91040d441fe5a846a49c9d98c02%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.