【发布时间】:2017-06-17 16:40:15
【问题描述】:
我正在使用 Heroku 来部署我的 Django 应用程序,我正在尝试使用以下模型将很长的数据放入表中(将数据添加到 content:
models.py:
class ContentModel(models.Model):
ref_id = models.CharField(primary_key=True, max_length=120, unique=True)
content = models.TextField() #<-------
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
def __str__(self):
return self.content
class Meta:
unique_together = ("content", "ref_id")
但我收到以下错误:
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
psycopg2.OperationalError: index row size 3496 exceeds maximum 2712 for index "editor_contentmodel_content_2192f49c_uniq"
HINT: Values larger than 1/3 of a buffer page cannot be indexed.
Consider a function index of an MD5 hash of the value, or use full text indexing.
我不确定这里的索引是什么意思,如果是用于搜索,我认为我不需要它,我想做的就是从表中检索数据。
它还要求我提供 MD5 哈希,所以在将内容添加到数据库之前我应该使用hashlib 吗?问题是我将 JSON 添加到 content
【问题讨论】:
标签: python django postgresql heroku