'Difference Django DB models using the ForeignKey to object with or without "to" statement?
I am new to Django and trying to understand someone else code. Where I am struggling with is the models.py and when to use a direct assignment of another object or when to use the "to" statement.
What is the difference between those statement?
model = models.ForeignKey('Car', on_delete=models.CASCADE, blank=True, null=True)
model = models.ForeignKey(to='Car', on_delete=models.CASCADE, blank=True, null=True)
Solution 1:[1]
The use of to is implicit for the first parameter ('Car'), I would omit it but it is also acceptable to explicitly include it. So those statements are equivalent.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | RedWheelbarrow |
