Opened 13 years ago

Closed 13 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.

Change History (1)

comment:1 by Aymeric Augustin, 13 years ago

Resolution: invalid
Status: newclosed

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?

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