Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No relations found" in psql after rails db:migrate succeeds

As a Rails novice, I'm following instructions in railscast #342 to set up a postgres database connection on my Mac.

I created a new rails project with

$ rails new blog -d postgresql

I edited the database yaml file to set the username and password.

I used psql to add the new user and password, and gave it permission to create tables: alter user blog create db

I created the db via

rake db:create:all

It succeeded and inside psql, doing \l to list schemas, I see all three schemas blog_test, blog_development and blog_production

I then do

$ rails g scaffold article name content:text

all looks good

I then do

$ rake db:migrate

I get messages showing success:

$ rake db:migrate

== 20150701220010 CreateArticles: migrating ===================================
-- create_table(:articles)
   -> 0.0128s
== 20150701220010 CreateArticles: migrated (0.0129s) ==========================

I set my search path to look at the schema:

set search_path to lcuff,public,blog_development;

show search_path:

search_path
---------------------------------
 lcuff, public, blog_development

But trying to find the table,

# \d

No relations found.

I've done the db:migrate VERSION=0 and it successfully reports that it drops the table, and then I create it again with db:migrate and it reports success.

If the first part hadn't worked, where it actually created the schema, I'd think I'm pointed to the wrong database somehow.

Ideas?

like image 914
Leonard Avatar asked Feb 09 '23 16:02

Leonard


1 Answers

You should first connect to the database before fetching the tables.

\connect blog_development

And then try giving \d to list all tables.

You can also try with \dt.

Example(Tested in my Project):

\connect my_db
You are now connected to database "my_db" as user "postgres".

my_db=# \d

                    List of relations
 Schema |             Name              | Type  |  Owner   
--------+-------------------------------+-------+----------
 public | access_managements            | table | postgres
 public | amenities                     | table | postgres
 public | city_coordinates              | table | postgres
 public | coapplicants                  | table | postgres

Source

like image 115
Pavan Avatar answered Mar 23 '23 21:03

Pavan