简体   繁体   中英

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. Thank you.

According to rails naming convention,

the table names should be the plural to the model names.

Example: User model table name should be users

As you said, you have a dump sql file,

first you should run db:schema:dump to dump the schema.

Next, if the table name of the dumped file is not according to the naming convention of rails, change the table_name using

self.table_name = "USER"

so, In your model,

class User < ApplicationRecord 
    self.table_name = "USER" 
end 

Now, User.all runs the command,

SELECT USER.* FROM USER

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM