Suppose I have a field f in my model defined as follows as a foreign key:
f = models.ForeignKey(AnotherModel)
When Django syncs database, the filed created in db will be called f_id
, automatically suffixed with '_id'.
The problem is I want this field in db named exactly as what I defined in model, f
in this case. How can I achieve that?
Well it turns out there's a keyword argument called
db_column
. If you want the field called 'f' in the database is just as simple as:Further reference:
https://docs.djangoproject.com/en/dev/ref/models/fields/#db-column