允许在 mysql 整数列中引用值吗?
考虑 table1 的表模式:
id: int country_id: int description: varchar(50)
和查询:
INSERT INTO table1(id, country_id, description) VALUES (1, '20', 'Test Desc');
这在 MySQL 4x 下可以工作,但在 MySQL 5x 下会失败(错误 1067 (42000): Invalid default value for .. ")。
我知道发生这种情况的原因 -
>country_id 是 int,因此不应被引用 使用这样的查询,我正在寻找快速修复,直到我有时间修复所有查询,
谢谢。
Consider the table schema for table1:
id: int country_id: int description: varchar(50)
and the query:
INSERT INTO table1(id, country_id, description) VALUES (1, '20', 'Test Desc');
This would work under MySQL 4x but will fail under MySQL 5x (ERROR 1067 (42000): Invalid default value for .. ").
I know the reason for this to happen - country_id is int and therefore should not be quoted. Is there a mysql switch under 5x somewhere to make it behave like 4x so the query won't fail?
I've inherited an application that uses queries like this and I'm looking for a quick fix until I can find the time to fix all the queries.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“20”没有问题。 MySql (5.x) 还将 '20' 转换为 20 并 =>这是一个有效的插入
There is no problem with '20'. MySql (5.x) also casts '20' to 20 and => this is a valid insert