django admin 在尝试更新记录时崩溃,但在插入新记录时不会崩溃
我遇到了一个奇怪的问题:
developemnt 的技术信息(生产将在 linux/apache/Mysql 上进行) macOS 2.6.6 蟒蛇2.6.1 Django 1.3 mysql 5.1 和 MySQLdb 将 python 连接到 MySQL...
我是 django 的新手,每个人都可以从过去的问题中看到...但需要变得非常强大,非常快...问题是它真的对我来说不太顺利......
好吧,对于这个问题。我正在做 django 教程(不是为了好玩,我需要快速学习它,因为我需要用它开发一个巨大的系统)。
到目前为止,我已经完成了所有教程以及添加管理员的阶段。
当我尝试编辑投票记录(如果有人知道 django 1.3 教程)时,网站崩溃,出现以下异常:
警告位于 /admin/polls/poll/2/ 字符串值不正确:第 1 行“change_message”列的“\xD7\xA9\xD7\x95\xD7\xA0...”
同一个表添加新记录没有问题,只需编辑一个... .
如果有人知道有关它的任何事情....
# Create your models here.
class Poll(models.Model): 问题= models.CharField(max_length=200) pub_date = models.DateTimeField('发布日期')
def __unicode__(self):
return self.question
def was_published_today(self):
return self.pub_date.date() == datetime.date.today()
这是模型,另一个是我看到的,我的 MySQL DB 是 latin1 而不是 UTF-8...python 是 unicode...也许这就是问题... 但是,
我仍然不明白为什么我可以添加记录但无法编辑它们......这不是奇怪的部分吗?
I'm having a weird problem:
technical info for developemnt (production will be on linux/apache/Mysql)
macosx 2.6.6
python 2.6.1
django 1.3
mysql 5.1
and MySQLdb to connect the python to the MySQL...
I'm new at django as every one can see from past questions...but need to get really strong at it, really fast...the problem is that it is really not that smooth for me...
OK, for the question. I'm doing the django tutorial (not for fun, i need to learn it really fast because i need to develop a huge system with it).
I did all the the tutorial untill now and at the stage where i added the admin.
When i try to edit the poll record (if any one know the django 1.3 tutrial) the site crashes with the following exception:
Warning at /admin/polls/poll/2/
Incorrect string value: '\xD7\xA9\xD7\x95\xD7\xA0...' for column 'change_message' at row 1
there is not problem with adding a new record to the same table, just to edit one....
if any one know's any thing about it....
# Create your models here.
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question
def was_published_today(self):
return self.pub_date.date() == datetime.date.today()
This is the model, and another this i saw, my MySQL DB is latin1 and not UTF-8...python is unicode....maybe that is the problem....
But still, i can't figure out why i can add records but can't edit them....isn't that the weird part?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了同样的问题,但使用的是 Django 1.4。我使用了photoionized的推荐,但适应了这个版本(其中
auth_message
消失了,但你可以在django_admin_log
中找到change_message
代码>)。所以:I was experiencing same issue but using Django 1.4. I used the recommendation of photoionized but adapted to this version (where
auth_message
is gone, but you can findchange_message
indjango_admin_log
). So:听起来像是数据库字符集问题。你能检查一下数据库中auth_message表的默认字符集吗?
如果您的表无法处理 utf8 它会抛出此错误。
Sounds like a database character set issue. Can you check the default character set of auth_message table in your database?
If your table can't handle utf8 it would throw this error.
打开 mysql shell 并运行以下命令:
上面是否有任何
utf8
值?假设这是 mysql 问题,请将数据库设置替换为 sqlite3:
Sync 并尝试再次输入一些数据。
Open your mysql shell and run the following:
Are there any
utf8
values from above?Assuming it's a mysql issue, swap out your db settings to sqlite3:
Sync and try to input some data again.
在表“django_admin_log”中找到列“change_message”。将字符集更改为默认的utf-8。完毕
Find the Column 'change_message' in the Table 'django_admin_log'. Change the character set to utf-8 default. Done