我找到了这样的东西:Rails: How to list database tables/objects using the Rails console?
这一行没问题:
ActiveRecord::Base.connection.tables
并返回所有表
但是
ActiveRecord::Base.connection.table_structure("users")
产生错误:
ActiveRecord::Base.connection.table_structure("projects")
我认为
table_structure
不是 Postgres 方法。
如何列出 Postgres 数据库的 Rails 控制台中表中的所有数据?
最佳答案
您可以直接从命令行从 postgres 获取此信息
psql your_development_database -c "\d"
-- lists all database tables
psql your_development_database -c "\d users"
-- lists all columns for a table; 'users' in this case
如果你想在 rails 控制台中查看模型属性
User.new
User.new.inspect
# or install the awesome_print gem for better output
ap User.new
关于sql - 在 Rails Console for PostgreSQL 的表中显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25835134/