I want to know what the difference between these two foreignkey definitions are.
(1) MyFKField = models.ForeignKey('MyModel')
(2) MyFKField = models.ForeignKey(MyModel)
I understand (I think…) that (1) MyModel needs to be defined in that same file and the other needs to be imported, but I’m unsure of the reason/benifits of doing it either way.
I had a look through the Django docs but couldnt find anything, and Im also not sure if this is the right place to ask, so apologies if not.
Cheers
Django docs states that you would use a string to (1):
model.ForeignKey('self'))model.ForeignKey('app.mymodel'))But in general, specifying the model class directly is clear where it’s coming from (2).