Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django中的Integrity错误(我认为是关于新的外键)_Python_Django_Web - Fatal编程技术网

Python django中的Integrity错误(我认为是关于新的外键)

Python django中的Integrity错误(我认为是关于新的外键),python,django,web,Python,Django,Web,我有post模型和profile模型在profile模型上我有一个OneToOneField这是我的profile模型: from django.db import models from django.contrib.auth.models import User class Profile(models.Model): GENDER_CHOICES = [('boy', 'پسر'), ('girl', 'دختر'), ('i prefer not to say', 'ترج

我有post模型和profile模型在profile模型上我有一个
OneToOneField
这是我的profile模型:

from django.db import models
from django.contrib.auth.models import User



class Profile(models.Model):
    GENDER_CHOICES = [('boy', 'پسر'), ('girl', 'دختر'), ('i prefer not to say', 'ترجیح میدهم نگویم')]


    user = models.OneToOneField(User, on_delete=models.CASCADE)
    profile_picture = models.ImageField(upload_to='profile_pictures', blank=True, default='default.jpg')
    name = models.CharField(max_length=30)
    age = models.IntegerField(default="0")
    birth_day = models.CharField(max_length=30)#DateField(blank=True)
    gender = models.CharField(max_length=20, choices=GENDER_CHOICES)
    address = models.CharField(max_length=30, blank=True, default="---")
    bio = models.TextField(max_length=300, blank=True, default="---")
    phone = models.IntegerField(blank=True, null=True)
    skills = models.TextField(max_length=200, blank=True, default="ترجیح میدهم نگویم")
    favorites = models.TextField(max_length=200, blank=True, default="ترجیح میدهم نگویم")
    favorite_books = models.TextField(max_length=200, blank=True, default="ترجیح میدهم نگویم")
    favorite_movies = models.TextField(max_length=200, blank=True, default="ترجیح میدهم نگویم")
    favorite_musics = models.TextField(max_length=200, blank=True, default="ترجیح میدهم نگویم")
    favorite_sports = models.TextField(max_length=200, blank=True, default="ترجیح میدهم نگویم")
这是我的帖子模型:

from django.db import models
# from django.contrib.auth.models import User
from django.utils import timezone
from django.urls import reverse
from taggit.managers import TaggableManager
from user.models import Profile


class Post(models.Model):
    STATUS_CHOICES = [('published', 'published'), ('draft', 'draft')]

    title = models.CharField(max_length=60)
    slug = models.CharField(max_length=120, unique=True)
    image = models.ImageField(blank=True, upload_to="posts_images", null=True)
    image_alt = models.CharField(max_length=35, blank=True, null=True)
    body = models.TextField()
    date = models.DateTimeField(auto_now_add=True)
    update = models.DateTimeField(auto_now=True)
    publish_date = models.DateTimeField(default=timezone.now)
    status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='published')
    author = models.ForeignKey(Profile, on_delete=models.CASCADE)
    tags = TaggableManager()

    published_manager = PublishedManager()

    def __str__(self):
        return self.title

    class Meat:
        ordering = ('-publish_date',)

    def get_absolute_url(self):
        return reverse('post:post_details', args=[self.slug,])
我可以更改以前的帖子并保存它们,但我不能添加新帖子,因为我会遇到这个错误

IntegrityError at /admin/post/post/add/

NOT NULL constraint failed: post_post.owner_id

您可以看到,在我添加配置文件模型之前,我将djangouser与带有post模型的foregkey连接,其变量为“owner”,但现在我删除了,但仍然得到了错误,而且当我迁移新配置文件时,我得到了一些类似错误的信息,但它们不是错误,而是一些类似警告之类的信息,谢谢帮助

显示您的表单请更改您的
Post
模型,并且不运行迁移吗?您在那里没有
owner\u id
字段!