Reputation: 1251
Basic Information
I have a rails app A that is connected to a mysql database hosted on dotcloud.com. Below is how my database.yml file looks like,
production:
adapter: mysql2
host: <host>
port: <port>
database: <database_name>
username: <username>
password: <password>
Until here it works fine, I can access the records in the database from A, do queries and stuff.
Now I have another rails app B that needs to be connected to the same database as A, so i simply copy and paste the exact same details above into the database.yml file in B. However, when I tried to go into the rails console on production, I can't seem to access the database. For example if I had a User Table, it will just say NameError: uninitialized constant User
.
Is this an access control issue? How should I go about debugging this problem?
Appreciate any advice.
Update
So I copy and paste the .rb and schema files from A to B. However I am getting uninitialized constant ActiveRecord (NameError)
when trying to access the database in rails console. Anyone know how to ?
Upvotes: 1
Views: 897
Reputation: 1251
I ended up creating a new rails app, and setup everything again. Copy the same database.yml config then did rake db:migrate, then include the necessary model files, went into rails console and it works now.
:)
Upvotes: 1
Reputation: 13404
Try to list your tables using:
ActiveRecord::Base.connection.tables
That should show if you can at least get to the database correctly.
Upvotes: 0
Reputation: 14694
Did you run the migrations for app B? Of course, the database is already set up but App B doesn't have a copy of the schema. So, you can either run the migrations in App B or copy the schema from App A to App B.
Upvotes: 0