使用mysql在django模型charfield中获取空白语句
我刚刚将 django 应用程序从 sqlite3 迁移到 mysql 5.1.41。我在模型中有一个像这样定义的 charfield:
class HostData(models.Model):
Host = models.CharField(max_length=50, null=True)
HostStatus = models.CharField(max_length=200, null=True)
Alarm = models.BooleanField()
除了 HostStatus 之外,一切都一样,它通常返回一个类似“Up, waiting”的字符串。然而在 mysql 中,它是空白的。我创建了字符集为 utf-8 的表。我做错了什么?提前致谢。
I just migrated my django application from sqlite3 to mysql 5.1.41. I have a charfield in a model defined like this:
class HostData(models.Model):
Host = models.CharField(max_length=50, null=True)
HostStatus = models.CharField(max_length=200, null=True)
Alarm = models.BooleanField()
Everything works the same except HostStatus, which usually returns a string like "Up, waiting". In mysql, however, it is blank. I created my table with character set to utf-8. What am I doing wrong? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我看不出该模型代码有什么问题。
您是如何将数据迁移到 MySQL 的?当您通过 django admin 输入数据时,它是否将数据输入到数据库中?
如果视图正在输入此数据,您可以发布视图代码吗?
I can't see anything wrong with that model code.
How have you migrated your data over to MySQL? When you enter data via the django admin, does it enter data into the db?
If a view is entering this data, can you post the view code.
问题在于我为模型分配值的方式。我不知道为什么它在 sqlite 中运行良好,但无论如何它都是糟糕的编码。这就是我正在做的:
我将其更改为:
一切都很好。
The issue was the way I was assigning the value to the model. I dont know why it worked well in sqlite, but it was bad coding anyways. This is what I was doing:
I changed this to:
And everything was ok.