ActiveRecord: List columns in table from console

前端 未结 8 1347
遥遥无期
遥遥无期 2020-12-22 23:21

I know that you can ask ActiveRecord to list tables in console using:

ActiveRecord::Base.connection.tables

Is there a command that would li

8条回答
  •  旧时难觅i
    2020-12-22 23:47

    If you are comfortable with SQL commands, you can enter your app's folder and run rails db, which is a brief form of rails dbconsole. It will enter the shell of your database, whether it is sqlite or mysql.

    Then, you can query the table columns using sql command like:

    pragma table_info(your_table);
    

提交回复
热议问题