首页 文章

django:无法将数据保存到模型中,psql错误

提问于
浏览
0

我有以下模型描述:

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"列|输入|修饰符
----------- ------------------------ --------------- -------------------------------------------------- ------ id |整数| not null default nextval('registration_userprofile_id_seq' :: regclass)about |文字|不是排名|整数| not null user_id |整数| not null avatar |字符变化(100)|国家|字符变化(2)| status_id |整数|索引:"registration_userprofile_pkey" PRIMARY KEY,btree(id)"registration_userprofile_user_id_key" UNIQUE,btree(user_id)外键约束:"registration_userprofile_status_id_fkey" FOREIGN KEY(status_id)REFERENCES registration_userrank(id)DEFERRABLE INITIALLY DEFERRED "registration_userprofile_user_id_fkey" FOREIGN KEY(user_id)REFERENCES auth_user(id)DEINDRABLE INITIALLY DEFERRED

我看到的错误代码是:

(,DataError('值类型字符变化太长(2)\ n',),)

回溯(最近一次调用最后一次):文件“/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(data)文件“/usr/lib/python2.5/site-packages/Django-1.1.1-py2.5.egg/django/core/servers/basehttp.py”,第416行,自写 . _write(data)文件“/usr/lib/python2.5/socket.py”,第274行,写入self.flush()文件“/usr/lib/python2.5/socket.py”,第261行,in flush self._sock.sendall(buffer)错误:(32,'Broken pipe')

我觉得它发生是因为我错误地更新了数据库以适应模型...但不确定是什么问题,以及如何解决它 . 相同的代码在mysql实例上本地工作...但我在prod上有psql ....

1 回答

  • 2

    我'm betting you'使用这个:http://djangosnippets.org/snippets/494/和[如tcarobruce所说] CountryField是一个2-char代码,代表国家 - 'FR','GB','US'等,你试图存储国家的完整字符串名称 .

相关问题