在Rails控制台中为PostgreSQL显示表中的数据
发布时间:2020-12-13 16:06:17 所属栏目:百科 来源:网络整理
导读:我找到这样的东西: Rails: How to list database tables/objects using the Rails console? 这条线很好: ActiveRecord::Base.connection.tables 并返回所有表 但 ActiveRecord::Base.connection.table_structure("users") 生成错误: ActiveRecord::Base.c
我找到这样的东西:
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控制台中的Model属性 User.new User.new.inspect # or install the awesome_print gem for better output ap User.new (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |