7 python django postgresql heroku python-3.x
运行django应用程序时遇到上述错误。但究竟需要改变什么?comment_body = models.TextField() 方面很可能是罪魁祸首,因为它存储长度可能不同的 reddit 评论。当我进行 git 克隆并在本地运行它时,奇怪的是它有效。
模型.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)
Run Code Online (Sandbox Code Playgroud)
编辑:
给出错误:value too long for type character varying(200)您应该查找 a 为max_length200 的模型字段。由于您有多个 max_length 设置为 200 的字段,因此您需要确定哪个模型和字段引发错误。检查堆栈跟踪,运行调试器和/或插入一些调试print(instance.__dict__)。一旦找到罪魁祸首,请将该字段扩展max_length为更大的内容或将其转换为TextField.
| 归档时间: |
|
| 查看次数: |
4518 次 |
| 最近记录: |