Yet, another stupid, pointless message from the wonderful Django.
Why am I getting the following message when I run the makemigrations
command:
django.db.utils.OperationalError: no such column: media_mediamodule.article_new_field
Is this not a “Duh” moment? I’m trying to add a new bloody category and it’s telling me that the column does not exist. Well it would bloody exist if you stopped faffing with silly, pointless “error” messages, and let me add the bloody column.
It’s like going into a supermarket for a pack of sugar and the store tells you that you don’t have a pack of sugar. Um duh – that’s why I’m going to the supermarket.
from django.db import models
import uuid, random, string
def generate_unique_id(charlimit):
”’This will generate a random set of numbers and letters which will be used to generate a unique URL for each object in the model.
'''
random_string = ''.join(random.choices(string.ascii_lowercase + string.digits, k=charlimit)) # Generates a random string
return f"{random_string}"
def generate_unique_uuid():
”’This will generate a random set of numbers and letters which are to be derrived from the UUID methodology, which will be used to generate a unique URL for each object in the model.
'''
return str(uuid.uuid4())[:8]
# Create your models here.
class MediaModule(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
article_identifier = models.CharField(max_length=50, default=generate_unique_id(12), unique=True, editable=False)
article_headline = models.CharField(max_length=100)
article_body = models.TextField()
article_synopsis = models.TextField(null=True)
article_journalist = models.CharField(max_length=20)
article_date = models.DateTimeField(auto_now=True)
article_image = models.ImageField(upload_to='assets')
article_image_summary = models.TextField(default="", null=True, blank=True)
article_new_field = models.TextField(default="", max_length=225)
def __str__(self):
return self.article_headline
Sometimes it’s like pulling teeth with Django, it really is. Some days it does as it’s told, other days it behaves like a senile person.
Why?