Code

Opened 3 years ago

Closed 3 years ago

#17418 closed Cleanup/optimization (invalid)

ForeignKey automatic attribute does not depend on db_column

Reported by: anonymous Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Here is an example:

class Author(models.Model):
    name = models.CharField(max_length=10)

class Book(models.Model):
    name = models.CharField(max_length=10)
    author = models.ForeignKey(Author, db_column="author_key")

As from django documentation it will create a column in the database by appending '_id' to the field name, in our case it will be 'author_id'. It will also create an attribute author_id for the Book's instance. The database column name can be overwritten by defining db_column, this is what I did in my example. However, I expect that attribute will be changed from author_id to author_key but it does not happen.

Attachments (0)

Change History (1)

comment:1 Changed 3 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

As its name implies, db_column only affects the name of the column in the database, not the name of the field in Python code.

If you were misled by the docs, could you tell us which paragraph confused you?

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.