IntegrityError(news_post.hashTag不得为NULL)

时间:2019-05-28 16:19:08

标签: django python-3.x

我正在部署用 Django == 1.8 Python == 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')),
            ],
        ),


0 个答案:

没有答案