Answer a question

Facing the above error when running the django app. What exactly needs to be changed though? The comment_body = models.TextField() aspect most probably is the culprit since it stores reddit comments which can be of varying lengths. When i do a git clone and run it on my local, strangely it works.

Heroku Logs

Models.py

from django.db import models

# Create your models here.
class Subreddit(models.Model):
    # Field for storing the name of a subreddit
    subreddit_name = models.CharField(max_length=200, unique=True)

    # Field for storing the time the model object was last saved
    last_updated = models.DateTimeField(auto_now=True)

class Submission(models.Model):
    subreddit = models.ForeignKey(Subreddit, on_delete=models.CASCADE)

    # The Reddit submission id of the object
    submission_id = models.CharField(max_length=200, unique=True)

    # Reddit Submission URL
    url = models.URLField(max_length=200)

    # Reddit Submission Title
    title = models.CharField(max_length=200)


class SubmissionComment(models.Model):
    # Parent submission object
    submission = models.ForeignKey(Submission, on_delete=models.CASCADE)

    # Text of the comment
    comment_body = models.TextField()

class Meme(models.Model):
    memeurl = models.URLField(max_length=200)

EDIT:

New error post char changed to 300, and migrations run locally and on heroku. New error but where is the error

Answers

Given the error: value too long for type character varying(200) you should look for model fields that have a max_length of 200. Since you have multiple fields with a max_length set to 200, you need to determine which model and field are throwing the error. Check the stacktrace, run a debugger and/or insert some debugging print(instance.__dict__)s. Once you find the culprit, extend that field's max_length to something larger or turn it into a TextField.

Logo

PostgreSQL社区为您提供最前沿的新闻资讯和知识内容

更多推荐