ForeignKey
This field is to represent the Foreign Key. Let's look at some methods this field allows.
- The interface of a field
ForeignKey
:
1 2 3 4 5 6 7 8 |
|
- Parameters:
model
: TheModel
that will be used in the relationship.name_in_table_fk
: The name of the attribute that will beFK
in the other model.unique
: Whether this field is going to be a single value or not.name_constraint
: Name for theForeign Key
constraint. If not passed, the default logic of the used database will be used.on_delete
: Action ON DELETE:CASCADE
,NO ACTION
,RESTRICT
,SET DEFAULT
andSET NULL
.on_update
: Action ON UPDATE:CASCADE
,NO ACTION
,RESTRICT
,SET DEFAULT
andSET NULL
.
Examples
Since this field is used to create some types of relationships, the examples of use of this field can be found in the documentation on OneToMany and ManyToMany.