I've got the following models:
title = models.CharField(max_length=100)
description = models.TextField()
date_posted = models.DateTimeField(default=timezone.now)
author = models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('post-detail', kwargs={'pk': self.pk})
class Ingredient(models.Model):
ingredients_recipe = models.ForeignKey(Post, on_delete=models.CASCADE)
type = models.CharField(max_length=50)
quantity = models.IntegerField()
measurement = models.CharField(max_length=50)
class MethodStep(models.Model):
methods_recipe = models.ForeignKey(Post, on_delete=models.CASCADE, null=True)
step = models.TextField()
When i try to run makemigrations
, i get no errors for the Ingredient
class, but on the MethodStep
class i get an error saying:
You are trying to add a non-nullable field 'methods_recipe' to methodstep without a default; we can't do that (the database needs something to populate existing rows).
Can someone help me? I'm not sure whats different about each of these classes which would mean the MethodStep
has an error but Ingredient
doesn't.
Edit: I've also tried deleting/clearing/removing the db but the error persists everytime makemigrations
is run.