Fix null=True vs blank=True on string fields

Django documentation suggests no using null=True, but
instead defaulting to the empty string.  It's
necessary of course to allow blank=True so that
users don't have to enter the field
This commit is contained in:
Maximilian Friedersdorff 2022-07-08 21:49:42 +01:00
parent 17e41a9e4c
commit 72e80817a5
2 changed files with 25 additions and 2 deletions

View file

@ -0,0 +1,23 @@
# Generated by Django 4.0.5 on 2022-07-08 20:49
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("posts", "0002_alter_comment_post_alter_post_img"),
]
operations = [
migrations.AlterField(
model_name="post",
name="body",
field=models.TextField(blank=True, default=""),
),
migrations.AlterField(
model_name="post",
name="title",
field=models.CharField(blank=True, default="", max_length=255),
),
]

View file

@ -17,8 +17,8 @@ class Post(models.Model):
posted = models.DateTimeField(auto_now_add=True)
public = models.BooleanField(default=False)
title = models.CharField(max_length=255, null=True)
body = models.TextField(null=True)
title = models.CharField(max_length=255, blank=True, default="")
body = models.TextField(blank=True, default="")
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)