活动记录> MySQL 适配器 >区分大小写
我正在使用一个 MySQL 数据库,该数据库具有大写的表/字段名称,如用户、机构等。由于数据库主机的操作系统是 Linux,标识符(如表名称)被视为区分大小写。因此,如果表名不大写将导致表不存在错误。
我试图解决的问题是 ActiveRecord 始终以小写形式构造标识符。因此,例如,如果使用“find”方法从Institution表中获取第一条记录,则生成的SQL将如下所示:
SELECT `institutions`.* FROM `institutions` LIMIT 1
这当然会导致Linux环境中的MySQL错误,因为它不区分大小写。
关于如何解决这个问题有什么想法吗?
提前致谢!
I am working with a MySQL database that has capitalized table/field names like Users, Institutions, etc. Because the operating system of the database host is Linux, identifiers (like the table names) are treated as case sensitive. So, failing to capitalize a table name will result in a table does not exist error.
The problem I am trying to solve is that ActiveRecord always constructs identifiers in lower case. So, for example, if use the "find" method to grab the first record from the Institution table, the resulting SQL will look like:
SELECT `institutions`.* FROM `institutions` LIMIT 1
This, of course, results in a MySQL error in a Linux environment because it is not case sensitive.
Any thoughts on how one might get around this issue?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为应该立即清除你。
Should clear you right up I think.
Rails 使用约定优于配置来确定模型中表的名称。
但您始终可以调整默认值以匹配您的旧数据库。
看看这里:
http://book.opensourceproject。 org.cn/lamp/ruby/railscook/opensource/0596527314/i_0596527314_chp_3_sect_20.html
和此处:
http://railsapi.com/doc/rails-v3.0.0/classes/ActiveRecord/Base.html#M001129
Rails use convention over configuration to determine the name of the table from a model.
But you can always tweak the default to match your legacy databases.
Have a look here:
http://book.opensourceproject.org.cn/lamp/ruby/railscook/opensource/0596527314/i_0596527314_chp_3_sect_20.html
and here:
http://railsapi.com/doc/rails-v3.0.0/classes/ActiveRecord/Base.html#M001129