django.db.utils.IntegrityError:列"类别"中的空值违反非空约束

时间:2018-03-18 02:02:36

标签: python django python-3.x

我已从我的field模型中删除了此Post,但在创建一个Post实例时,它仍然会出现此错误:

    return self.cursor.execute(sql, params)
  File "/home/james/app/env/lib/python3.5/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/james/app/env/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/james/app/env/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: null value in column "category" violates not-null constraint

当我从category模型中移除Post并执行makemigrations& migrate,它在我的migrations文件夹中成功生成了此文件:

0002_remove_post_category

# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2018-03-16 22:56
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('post', '0001_initial'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='post',
            name='category',
        ),
    ]

所以它不应该再造成问题,但它仍然存在。

知道为什么吗?

0 个答案:

没有答案