guys i'm getting an error as you should have a default value to models:author,body,created,updated and here is my models.py configuration
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
# Create your models here.
class post(models.Model):
STATUS_CHOICE=(
('draft','DRAFT'),
('published','Published'),
)
title=models.CharField(max_length=250)
slug=models.SlugField(max_length = 250,unique_for_date=1)
author=models.ForeignKey(User,related_name='blog_posts')
body=models.TextField()
publish=models.DateTimeField(default=timezone.now)
created = models.DateTimeField(auto_now_add=True)
updated=models.DateTimeField(auto_now=True)
status = models.CharField(max_length=10,
choices = STATUS_CHOICE,
default='draft')
class Meta:
ordering = ('-publish',)
def __str__(self):
return self.title
and this is the error while migrating the database:
You are trying to add a non-nullable field 'body' to post without a default; we can't do that (the database needs something to populate
existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
2) Quit, and let me add a default in models.py
Select an option
i'm not sure what are the default values for those models and the configuration is same as it is mentioned in book but i'm still getting an error any kind of help is appreciated thanks in advance NOTE:this is a blog application and when i tried to add random default values to the models i'm getting this error: updated models.py:
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
# Create your models here.
class post(models.Model):
STATUS_CHOICE=(
('draft','DRAFT'),
('published','Published'),
('admin','admin'),
)
title=models.CharField(max_length=250)
slug=models.SlugField(max_length = 250)
author=models.ForeignKey(User,related_name='blog_posts')
body=models.TextField(default='draft')
publish=models.DateTimeField(default=timezone.now)
created = models.DateTimeField(auto_now_add=True,default=timezone.now)
updated =models.DateTimeField(auto_now=True,default=timezone.now)
status = models.CharField(max_length=10,
choices = STATUS_CHOICE,
default='draft')
class Meta:
ordering = ('-publish',)
def __str__(self):
return self.title
and the error now is :
ERRORS:
myblog.post.created: (fields.E160) The options auto_now, auto_now_add, and default are mutually exclusive. Only one of these options may
be present.
myblog.post.updated: (fields.E160) The options auto_now, auto_now_add, and default are mutually exclusive. Only one of these options may
be present
DateTimeField