Opened 8 months ago

Closed 8 months ago

Last modified 8 months ago

#22889 closed Cleanup/optimization (fixed)

Proper handling of to_field in deconstruct for AUTH_USER_MODEL foreign key

Reported by: timo Owned by: nobody
Component: Migrations Version: 1.7-beta-2
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

to_field shouldn't appear in the migration for a ForeignKey to settings.AUTH_USER_MODEL, otherwise the migration isn't usable if settings.AUTH_USER_MODEL uses a primary key with a name different than 'id'.

It's not necessary to include the field name, the default behavior of models.ForeignKey is to look up the primary key field name from the target model.

from this pull request.

Change History (3)

comment:1 Changed 8 months ago by Tim Graham <timograham@…>

In 68b89f4d13b69771b232c1fcb0fb598000b6eb98:

[1.7.x] Removed 'to_field' from ForeignKey(settings.AUTH_USER_MODEL) in admin's initial migration.

This enables using a custom user model with a primary key with a name
different than 'id'; refs #22889.

Backport of bcd2e6c697 from master

comment:2 Changed 8 months ago by Andrew Godwin <andrew@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 0b571753a89f2a7a34c76dea5ee81f821b980779:

Fixed #22889: Unneeded to_field in fk.deconstruct causing swap issues

comment:3 Changed 8 months ago by Andrew Godwin <andrew@…>

In e4c9ccdbb5295c952a0ca12f988ae1b2164b1623:

[1.7.x] Fixed #22889: Unneeded to_field in fk.deconstruct causing swap issues

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