I've created the following ForeignKey field in my Model under a class called "Activity"
related_workoutrecord = models.ForeignKey(WorkoutRecord, null=True, blank=True)
The ForeignKey is related to a class called WorkoutRecord which should be allowed to be blank.
After adding this column I ran South and got the following error message:
NameError: name 'WorkoutRecord' is not defined
Any thoughts on what's going on? I've confirmed 'WorkoutRecord' is a class in my model.
Do I need to write WorkoutRecord as a string (with quotes) for example:
related_workoutrecord = models.ForeignKey('WorkoutRecord', null=True, blank=True)
I appreciate the feedback
As per my comment, make sure the class 'Activity' has access to the class 'WorkoutRecord'.
The error means what it says, that WorkoutRecord is not defined in your Activity class.
Check these two things first:
1) Did you import it?
2) Was WorkoutRecord defined before Activity?
The WorkoutRecord class must be defined before (i.e. above) the Activity class, in order to use a reference to the class without quotes. If there are circular references between the classes, then using the quoted string version will work to get a lazy reference to the class defined later in your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With