首页 > 解决方案 > IntegrityError(news_post.hashTag 可能不为 NULL)

问题描述

我正在部署我的网站,它是用Django==1.8Python==3.6编写的。当我第一次创建项目模型时,我在表Post中添加了一个名为hashtag的列,因此删除此列后,我的Post模型类如下所示:

class Post(models.Model):
    league = models.ForeignKey(League, on_delete=models.CASCADE, related_name='$
    club = ChainedForeignKey(
        Club,  
        chained_field='league', 
        chained_model_field='league',  
        show_all=False,  
    )
    player = ChainedForeignKey(
        Player,  
        chained_field='club',  
        chained_model_field='club',  
        show_all=False,  
    )
    title = models.CharField(max_length=255)
    body = models.TextField(max_length=4000)
    img = models.ImageField()
    created_at = models.DateTimeField(auto_now_add=True)
    created_by = UserForeignKey(auto_user_add=True, verbose_name='The user that is automatically assigned', related_name='posts')

如您所见,没有名为hashtag的列。

每当我想在我的网站上添加帖子时,它都会说

IntegrityError at /admin/news/post/add/
news_post.hashTag may not be NULL
Request Method: POST
Request URL:    http://68.183.188.14:8000/admin/news/post/add/
Django Version: 1.8
Exception Type: IntegrityError
Exception Value:    
news_post.hashTag may not be NULL
Exception Location: /home/firdavsbek/futbik_version_7/djangoen/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py in execute, line 318
Python Executable:  /home/firdavsbek/futbik_version_7/djangoen/bin/python
Python Version: 3.6.8
Python Path:    
['/home/firdavsbek/futbik_version_7',
 '/home/firdavsbek/futbik_version_7/djangoen/lib64/python36.zip',
 '/home/firdavsbek/futbik_version_7/djangoen/lib64/python3.6',
 '/home/firdavsbek/futbik_version_7/djangoen/lib64/python3.6/lib-dynload',
 '/usr/lib64/python3.6',
 '/usr/lib/python3.6',
 '/home/firdavsbek/futbik_version_7/djangoen/lib/python3.6/site-packages']
Server time:    Вт, 28 Май 2019 20:35:54 +0500

但没有你以前见过的专栏......

我所做的只是python manage.py makemigrations news(this is my app name)python manage.py migrate,就是这样!

我无法解决这个问题,如果您有任何想法,我真的非常感谢您!

它是python manage.py showmigrations命令的输出:

 [X] 0001_initial
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
news
 [X] 0001_initial
sessions
 [X] 0001_initial

它是迁移文件夹中的00011_initial.py文件:

from __future__ import unicode_literals

from django.db import models, migrations
import smart_selects.db_fields
import django.db.models.deletion
import django_userforeignkey.models.fields
from django.conf import settings


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Post',
            fields=[
                ('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
                ('title', models.CharField(max_length=255)),
                ('title_en', models.CharField(max_length=255, null=True)),
                ('title_ru', models.CharField(max_length=255, null=True)),
                ('body', models.TextField(max_length=4000)),
                ('body_en', models.TextField(max_length=4000, null=True)),
                ('body_ru', models.TextField(max_length=4000, null=True)),
                ('img', models.ImageField(upload_to='')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('club', smart_selects.db_fields.ChainedForeignKey(to='news.Club', chained_field='league', chained_model_field='league')),
                ('created_by', django_userforeignkey.models.fields.UserForeignKey(verbose_name='The user that is automatically assigned', blank=True, null=True, editab$
                ('league', models.ForeignKey(blank=True, null=True, related_name='posts', to='news.League')),
                ('player', smart_selects.db_fields.ChainedForeignKey(to='news.Player', chained_field='club', chained_model_field='club')),
            ],
        ),


标签: djangopython-3.x

解决方案


推荐阅读