P
P
PyChan2020-05-25 19:47:47
Django
PyChan, 2020-05-25 19:47:47

Why is there a django.db.utils.IntegrityError migration error?

I have 3 models:
from django.db import models
from django.db.models import AutoField, DateField, CharField, ForeignKey, DecimalField, TextField

class Marks(models.Model):
    id = AutoField(primary_key=True)
    name = CharField(max_length=150)
    objects = models.Manager()


class Cats(models.Model):
    id = AutoField(primary_key=True)
    name = CharField(max_length=150)
    location = CharField(max_length=150, default=None, null=True, blank=True)
    objects = models.Manager()


class Items(models.Model):
    id = AutoField(primary_key=True)
    name = CharField(max_length=150)
    marks = ForeignKey(Marks, on_delete=models.DO_NOTHING)
    category = ForeignKey("Cats", on_delete=models.DO_NOTHING)
    price = DecimalField(max_digits=7, decimal_places=2)
    previous_price = DecimalField(max_digits=7, decimal_places=2)
    article_number = CharField(max_length=150)
    description = TextField()
    picture = CharField(max_length=500)
    objects = models.Manager()

Into another form
class ItemsForm(ModelForm):
    class Meta:
        model = Items
        fields = ['name', 'marks', 'category', 'picture', 'article_number', 'price', 'previous_price']

When executing makemigrations, everything is ok, but when migrating, an error pops up:
django.db.utils.IntegrityError: ERROR: column "location" contains NULL values
​​Please help me fix the error, otherwise I don't know what to do anymore

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2020-05-25
@PyChan

Why is default=None here?

location = CharField(max_length=150, default=None, null=True, blank=True)

remove - here it is not necessary to
delete the migration and recreate it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question