0

Is there a simple way to visualize the tables that are created for postgres databases in Heroku? I am trying to see what columns have been for my Rails app without having to go through all of my database migrations.

6
  • 1
    Just look at your schema.rb file. That is, assuming your local db and Heroku db are migrated to the same state. Commented Oct 29, 2017 at 16:31
  • The reason I am having issues is because I deleted some of my db migration files (I know, bad idea) and can only run heroku run:detached rake db:migrate which ends up not creating all of the columns I want. Commented Oct 29, 2017 at 16:33
  • Have you looked at your schema file? Commented Oct 29, 2017 at 16:35
  • Yes, but I am pretty sure the schema file in my development environment is different from my schema file in the production environment. I am getting the following error: NoMethodError (undefined method 'titleize' for nil:NilClass) when I am trying to titleize user's first and last names. This is working in my development environment, but not in production which is leading me to think that the schema files are different. Commented Oct 29, 2017 at 16:37
  • Nope. The nil error does not suggest a missing relation (table). If the table didn't exist, you'd be getting a missing relation error from the database. And, if the class didn't exist, you'd be getting a constant lookup error. Commented Oct 29, 2017 at 16:44

2 Answers 2

2

To view your tables you can run heroku pg:psql to fire up a Postgres console. Then just type \d to view your tables or if you want to get details from a particular table just run \d tablename.

Or, as @jvillian suggested you can view your schema.rb file that's deployed to your Heroku server.

$ heroku run bash
$ cat db/schema.rb
Sign up to request clarification or add additional context in comments.

5 Comments

Good ones! I'm thinking this is an XY problem, though. "I deleted some migrations and now I'm getting a NoMethodError so I infer my tables are messed up..." Doesn't quite sound right, y'know?
haha absolutely. In terms of "checking" which tables were migrated and which are not heroku pg:psql to view them would help right? he then just needs to compare what tables are migrated against his local environment.
To belabor the point, if he had munged his database and/or models, then he wouldn't be getting the NoMethodError (undefined method 'titleize' for nil:NilClass). That's a missing data problem. Not a missing table/field problem. Or am I thinking about that wrong?
No I think you're right because if it was a table/field issue you wouldn't get that kind of error correct ?
Correct. Missing table would give a missing relation error at the DB level. Missing column would give unknown attribute error. Or some such things. But, not the error he's getting.
0

I found that the easiest way to solve this problem is to do heroku pg:psql and then do \d users to look at my table named "users". It turns out I have migrated the columns first_name and last_name, so I have solved the problem I posted about.

I'm still trying to figure out why I am running into the NoMethodError (undefined method 'titleize' for nil:NilClass). If you are having trouble with this issue and this answer does not help you, check out the comments between jillian and Cyzanfar. They have good insights into how a postgres database works with Heroku.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.