Django ForeignKey null = true
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)
What schema changes are taking place models.ForeignKey('Story', null = True)
?
I read from the docs:
I want to use remove () and clear () and that is part of the documentation.
To prevent database inconsistency, this method only exists for ForeignKey objects where null = True. If the associated field cannot be set to None (NULL), then the object cannot be removed from the relationship without being added to another. In the above example, removing e from b.entry_set () is equivalent to doing e.blog = None, but because the ForeignKey blog does not have a null = True value, this is not correct.
+3
source to share
1 answer