3
from django.db import models
class Story(models.Model):
id = models.IntegerField(primary_key=True)
news_type = models.CharField(max_length=255,null=True)
category_id = models.CharField(max_length=255,null=True)
title = models.CharField(max_length=255,null=True)
created = models.DateTimeField(null=True)
author = models.CharField(max_length=255, null=True)
author_title = models.CharField(max_length=255, null=True)
image_caption = models.TextField(null=True)
image_credit = models.CharField(max_length=255,null=True)
image_full_url = models.CharField(max_length=255,null=True)
body = models.TextField(null=True)
summary = models.TextField(null=True)
video_id = models.CharField(max_length=255,null=True)
external_url = models.CharField(max_length=255,null=True)
order = models.IntegerField(null=True)
class StoryFactBox(models.Model):
story = models.ForeignKey('Story', null = True)
body = models.TextField()
class StoryKeyword(models.Model):
story = models.ForeignKey('Story', null = True)
keyword = models.CharField(max_length=255)
models.ForeignKey('Story', null = True)
會導致什麼模式更改?django ForeignKey null = true
我從文檔閱讀:
我想用remove()方法和明確的(),這是文件的一部分。
爲了防止數據庫不一致,該方法只存在於ForeignKey對象,其中null = True。如果相關字段不能設置爲無(NULL),則不能將對象從關係中刪除而不添加到另一個。在上面的例子中,從b.entry_set()中刪除e相當於做e.blog = None,並且因爲博客ForeignKey沒有null = True,所以這是無效的。