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/utils.py, line 89, in _execute
Python Executable:	/opt/venv/bin/python
Python Version:	3.8.16
Python Path:	
['/app',
 '/opt/venv/bin',
 '/nix/store/9493ngfjwisjm5f5s5ld5m34rdy431ic-python3-3.8.16/lib/python38.zip',
 '/nix/store/9493ngfjwisjm5f5s5ld5m34rdy431ic-python3-3.8.16/lib/python3.8',
 '/nix/store/9493ngfjwisjm5f5s5ld5m34rdy431ic-python3-3.8.16/lib/python3.8/lib-dynload',
 '/opt/venv/lib/python3.8/site-packages',
 '/opt/venv/lib/python3.8/site-packages/odf',
 '/opt/venv/lib/python3.8/site-packages/odf',
 '/opt/venv/lib/python3.8/site-packages/odf',
 '/opt/venv/lib/python3.8/site-packages/odf',
 '/opt/venv/lib/python3.8/site-packages/odf',
 '/opt/venv/lib/python3.8/site-packages/odf',
 '/opt/venv/lib/python3.8/site-packages/odf']
Server time:	Sun, 23 Apr 2023 10:10:10 +0000

Here is my models.py 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(
        EnglishArticle,
        related_name="french_article",
        blank=True,
        null=True,
        on_delete=models.CASCADE)

    class Meta:
        verbose_name_plural = 'French Articles'    


    def __str__(self):
        return self.title

 

message profile
Admin
2023-04-23

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

Tags

#python #django

Thread detail

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

DEVMAESTERS

Newsletter

Services

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

Contact

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: abubakarzakari1703@gmail.com

Copywright@devmaesters.com
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.