Getting error in django models while using foreign key

I am using foreign key in django models. But getting error. models.py:

class subscription(models.Model):
  duration_choice = (
    ("Monthly", "Monthly"),
    ("1 Year", "1 Year"),
    ("2 Year", "2 Year"),
  )
  Duration = models.CharField(max_length=100,choices=duration_choice)
  Price=models.IntegerField(default=0)

  def __str__(self):
      return self.Duration


class pro_Members(models.Model):
  subscription_type = models.ForeignKey(subscription,on_delete=models.CASCADE, default="")
  start_date=models.DateField(blank=True, null=True)
  expire_date= models.DateField(blank=True, null=True)
  is_active=models.BooleanField(default=False)

I used subscription models as foreign key in pro_members model. But getting an error.

column firmApp_pro_members.subscription_type_id does not exist
LINE 1: SELECT "firmApp_pro_members"."id", "firmApp_pro_members"."su...

anyone here can help. I tried my best but can not solve it.

when you add a new field into your Model Django tries to add this field to exist objects you can solve this like this:

class pro_Members(models.Model):
    subscription_type = models.ForeignKey(subscription,on_delete=models.CASCADE, default="", blank=True, null=True)

and then

> python manage.py makemigrations
> python manage.py migrate

and change back to:

class pro_Members(models.Model):
    subscription_type = models.ForeignKey(subscription,on_delete=models.CASCADE, default="")
Back to Top