Opened 2 years ago

Closed 2 years ago

#33823 closed Cleanup/optimization (fixed)

inspectdb should generate related_name on same relation links.

Reported by: whysage Owned by: whysage
Component: Core (Management commands) Version: dev
Severity: Normal Keywords:
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

Hi!

After models generation with inspectdb command we have issue with relations to same enities


module.Model.field1: (fields.E304) Reverse accessor for 'module.Model.field1' clashes with reverse accessor for 'module.Model.field2'.
HINT: Add or change a related_name argument to the definition for 'module.Model.field1' or 'module.Model.field2'.
*

Maybe we can autogenerate

related_name='attribute_name'

to all fields in model if related Model was used for this table

Change History (10)

comment:1 by whysage, 2 years ago

FIrst solution variant was - https://github.com/django/django/pull/15816
But now I see it is not correct.
I'll be back with new pull request

Last edited 2 years ago by whysage (previous) (diff)

comment:3 by whysage, 2 years ago

Has patch: set

comment:4 by Mariusz Felisiak, 2 years ago

Needs tests: set
Owner: changed from nobody to whysage
Status: newassigned
Summary: Inspectdb add related_name on same relation linkinspectdb should generate related_name on same relation links.
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization
Version: 4.0dev

Sounds reasonable. Tests are required.

in reply to:  4 ; comment:5 by whysage, 2 years ago

Replying to Mariusz Felisiak:

Sounds reasonable. Tests are required.

Hi Mariusz Felisiak!

Thank you for reply.

Now I should add some unit tests?

in reply to:  5 ; comment:6 by Mariusz Felisiak, 2 years ago

Now I should add some unit tests?

Yes, please.

in reply to:  6 comment:7 by whysage, 2 years ago

Replying to Mariusz Felisiak:

Now I should add some unit tests?

Yes, please.

ok

in reply to:  6 comment:8 by whysage, 2 years ago

Replying to Mariusz Felisiak:

Now I should add some unit tests?

Yes, please.

Test added:
https://github.com/django/django/pull/15819/commits/085896099ba04e86ed8cd54779e1daf5079dacd5

comment:9 by Mariusz Felisiak, 2 years ago

Needs tests: unset
Triage Stage: AcceptedReady for checkin

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In 3926e35a:

Fixed #33823 -- Made inspectdb generate unique related_name when reverse accessor clashes.

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