我已从我的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',
),
]
所以它不应该再造成问题,但它仍然存在。
知道为什么吗?