Reputation: 652
I have the following model in Django:
class Priority(models.Model):
task = models.ForeignKey(Task, on_delete=models.CASCADE)
priority = models.PositiveSmallIntegerField
However, when I run makemigrations and migrate, the field priority ( models.PositiveSmallIntegerField) doesn't appear in mysql table and I cannot create object of this model. Why?
Upvotes: 1
Views: 45
Reputation: 476584
Because you did not construct a field, you only passed a reference to that class, you need to add brackets (()
) to make the call:
class Priority(models.Model):
task = models.ForeignKey(Task, on_delete=models.CASCADE)
priority = models.PositiveSmallIntegerField()
# call the constructor ^^
If you do not call the constructor, you have set priority
as a reference to the PositiveSmallIntegerField
class, not as a PositiveSmallIntegerField
object.
Upvotes: 2