Answer the question
In order to leave comments, you need to log in
How to get rid of migrations error in Django?
I am using postgresql. Added an additional Techgroup model and created a foreignkey for it in the existing Technology table. I get an error when I try to apply migrations.
django.db.utils.IntegrityError: column "group_id" contains null values
class Techgroup(models.Model):
""" Group of technology """
name = models.CharField('group_name', max_length=32, unique=True)
def __str__(self):
return self.name
class Technology(models.Model):
"""Technologies."""
name = models.CharField('technology name', max_length=32, unique=True)
group = models.ForeignKey(Techgroup, on_delete=models.CASCADE, related_name="group")
def __str__(self):
return self.name
Answer the question
In order to leave comments, you need to log in
- change field to
- make a migration.
- run through the objects of the Technology model, assigning the appropriate Group
- make another migration, changing the field to
group = models.ForeignKey(Techgroup, on_delete=models.CASCADE, related_name="group")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question