Opened 10 years ago

Closed 10 years ago

Last modified 3 years ago

#22889 closed Cleanup/optimization (fixed)

Proper handling of to_field in deconstruct for AUTH_USER_MODEL foreign key

Reported by: Tim Graham 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 (4)

comment:1 by Tim Graham <timograham@…>, 10 years ago

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 by Andrew Godwin <andrew@…>, 10 years ago

Resolution: fixed
Status: newclosed

In 0b571753a89f2a7a34c76dea5ee81f821b980779:

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

comment:3 by Andrew Godwin <andrew@…>, 10 years ago

In e4c9ccdbb5295c952a0ca12f988ae1b2164b1623:

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

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

In ee3b719a:

Refs #32675 -- Removed to_field from ForeignKeys in contrib apps' migrations.

Refs #22889.

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