[英]Mysql tables in upper case in ror
I have created three tables and its attributes in upper case.One of my tables is:USER and its attributes are:NAME,ADDRESS.I am able to insert the data from the mysql server and the data is inserted successfully.My problem is that through rails console,i am unable to access the tables.Please specify what to do and notify me where have done mistake.我创建了三个表及其大写属性。我的一个表是:USER,它的属性是:NAME,ADDRESS。我能够从 mysql 服务器插入数据并且数据插入成功。我的问题是通过 Rails 控制台,我无法访问表。请指定要做什么并通知我哪里出错了。 Thank you.
谢谢你。
According to rails naming convention,根据 Rails 命名约定,
the table names should be the plural to the model names.表名应该是模型名的复数。
Example: User
model table name should be users
例子:
User
模型表名应该是users
As you said, you have a dump sql
file,正如你所说,你有一个转储
sql
文件,
first you should run db:schema:dump
to dump the schema.首先你应该运行
db:schema:dump
来转储模式。
Next, if the table name of the dumped file is not according to the naming convention of rails, change the table_name
using接下来,如果转储文件的表名不符合 rails 的命名约定,请使用以下命令更改
table_name
self.table_name = "USER"
so, In your model,所以,在你的模型中,
class User < ApplicationRecord
self.table_name = "USER"
end
Now, User.all
runs the command,现在,
User.all
运行命令,
SELECT USER.* FROM USER
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.