Django error value too long for type character varying(50)

I get the error below when I try to add a new article to my site

value too long for type character varying(50)
Request Method:	POST
Django Version:	4.0.4
Exception Type:	DataError
Exception Value:	
value too long for type character varying(50)
Exception Location:	/opt/venv/lib/python3.8/site-packages/django/db/backends/, line 89, in _execute
Python Executable:	/opt/venv/bin/python
Python Version:	3.8.16
Python Path:	
Server time:	Sun, 23 Apr 2023 10:10:10 +0000

Here is my file content

class EnglishArticle(models.Model):
    author = models.ForeignKey(Author, related_name='author',on_delete=models.SET_NULL, null=True) 
    slug = models.SlugField()
    title = models.CharField(max_length=400)
    body = RichTextUploadingField(default='Empty Content')
    date_created = models.DateField()
    published = models.BooleanField(default=False)
    image = models.ImageField(blank = True, null = True)
    reading_time = models.IntegerField()
    views = models.IntegerField(default=0)

    class Meta:
        verbose_name_plural = 'Articles'

    def __str__(self):
        return self.title

    def save(self, *args, **kwargs):
        title = self.title.lower()
        x = ['@', '#', '?', "/", ".", ",", "&", "!","|","-","_"]
        z ="".join(filter(lambda char: char not in x, title)) 
        self.slug = re.sub(r"\s+", '-', z)
        super().save(*args, **kwargs)

class FrenchArticle(models.Model):
    title = models.CharField(max_length=400)
    body = RichTextUploadingField(default='Empty Content')
    french_article = models.OneToOneField(

    class Meta:
        verbose_name_plural = 'French Articles'    

    def __str__(self):
        return self.title


message profile

Django by default assigns a max length of 50 characters to a slugfield, if you will like to add a slug with higher number of characters then you have to specify a max length for thr slugfield as shown below

slug = models.SlugField(max_length=400)


Add Message

Click on the button below to add a new message to this thread


#python #django

Thread detail

Satus: Open
Messages: 1Started: 2023-04-23




Frontend Development |Backend Development |Full Website Development |Bootstrap Website upgrades | Website Debbugging | Website Hosting & deployment


Interested in hiring me or collaborating with me on a project, click on any of the links below to get my social media handle

Or contact me via Tel: (+234)-806-225-7480 | Email:
Privacy Policy

By using our website,
you agree that devmaesters can store cookies on your device and disclose information in accordance with our privacy policy.