【发布时间】:2011-02-27 15:25:18
【问题描述】:
我描述了以下模型:
class UserProfile(models.Model):
avatar = models.ImageField(blank = True, upload_to='files')
about = models.TextField(blank=True)
rank = models.IntegerField(default = 1)
solvedProblems = models.ManyToManyField(Composition, blank=True)
user = models.ForeignKey(User, unique=True)
country = CountryField(blank = True)
status = models.ForeignKey(UserRank)
UserRank 在哪里:
class UserRank(models.Model):
rankName = models.CharField(max_length = 300)
upLimit = models.IntegerField()
downLimit = models.IntegerField()
我在描述模型后添加了状态、国家和头像字段,所以通过sql更新了数据库。
现在数据库看起来是这样的:
chess_problems=# \d registration_userprofile;
表“public.registration_userprofile”
专栏 |类型 |修饰符
-----------+------------+------------- -------------------------------------------------- --------
编号 |整数 |不为空默认 nextval('registration_userprofile_id_seq'::regclass)
关于 |正文 |不为空
排名 |整数 |不为空
用户 ID |整数 |不为空
头像 |字符变化(100) |
国家 |字符变化(2) |
status_id |整数 |
索引:
“registration_userprofile_pkey”主键,btree (id)
"registration_userprofile_user_id_key" 唯一,btree (user_id)
外键约束:
"registration_userprofile_status_id_fkey" 外键 (status_id) 参考registration_userrank(id) DEFERRABLE INITIALLY DEFERRED
"registration_userprofile_user_id_fkey" FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED
我看到的错误代码是:
(, DataError('value too long for type character varying(2)\n',), )
Traceback(最近一次调用最后一次): 运行中的文件“/usr/lib/python2.5/site-packages/Django-1.1.1-py2.5.egg/django/core/servers/basehttp.py”,第 280 行 self.finish_response() 文件“/usr/lib/python2.5/site-packages/Django-1.1.1-py2.5.egg/django/core/servers/basehttp.py”,第 320 行,finish_response self.write(数据) 文件“/usr/lib/python2.5/site-packages/Django-1.1.1-py2.5.egg/django/core/servers/basehttp.py”,第 416 行,写入 self._write(数据) 文件“/usr/lib/python2.5/socket.py”,第 274 行,写入 self.flush() 文件“/usr/lib/python2.5/socket.py”,第 261 行,刷新 self._sock.sendall(缓冲区) 错误: (32, 'Broken pipe')
我觉得发生这种情况是因为我错误地更新了数据库以适应模型...但不确定出了什么问题,以及如何解决它。相同的代码在 mysql 实例上本地工作......但我在 prod 上有 psql......
【问题讨论】:
-
能否请您缩进一点您的代码或数据库架构?
-
CountryField是如何定义的?在数据库中,看起来就是character varying(2)。您是否在该字段中插入更长的字符串? -
非常感谢大家。我增加了存储国家代码的字段,胜利是我的!!!!!!
标签: django postgresql