this is my model:
from django.db import models
class Topic(models.Model):
name = models.CharField(max_length=200)
def __str__(self):
return self.name
class Article(models.Model):
topic = models.ForeignKey(Topic, on_delete=models.CASCADE)
title = models.CharField(max_length=6000)
featured_image = models.ImageField(null=True,blank=True, default="default.jpg")
# i want to add this filed
content = models.TextField()
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
def __str__(self):
return self.title
i installed python -m pip install pillow and this is my setting configuration:
import os
STATIC_URL = '/static/'
STATICFILES_DIRS = [
BASE_DIR / 'static'
]
in the admin panel i am expecting the apparition of featured image filed that sets the image with the default.jpg
if the on the article creation the admin doesn’t insert a image.
After i run python manage.py makemigrations
it is always giving me this:
It is impossible to change a nullable field ‘topic’ on article to non-nullable without providing a default. This is because the database needs something to populate existing rows.
Please select a fix:
Provide a one-off default now (will be set on all existing rows with a null value for this column)
Ignore for now. Existing rows that contain NULL values will have to be handled manually, for example with a RunPython or RunSQL operation.
Quit and manually define a default value in models.py.
Select an option:
No matter what i pick i still don’t see the filed in the Django admin
Mihaela Guja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.