J
J
Jekson2019-07-23 17:12:29
PostgreSQL
Jekson, 2019-07-23 17:12:29

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

models.py
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

How to get around this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2019-07-23
@Lepilov

- 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 question

Ask a Question

731 491 924 answers to any question