Reputation: 41
I am making a Rails API using jbuilder to serve as my database for a React app I'm building. I am using PostgreSQL. I can get the index.json.jbuilder view to work on my local server:
{
"owners": [
{
"first_name": "Alex",
"last_name": "Hardy",
"revenue": 100000,
"audit_score": 89,
"passing": true,
}, ...........
{
But these instances are not going to Heroku's server. I have created the heroku app, pushed my app to heroku (git push heroku master) , and migrated the database with:
heroku run rake db:migrate
It has stored the tables because when I run:
Heroku pg:info
I get:
Plan: Hobby-dev
Status: Available
Connections: 2/20
PG Version: 9.6.2
Created: 2017-07-26 19:09 UTC
Data Size: 7.4 MB
Tables: 3
Rows: 2/10000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
Add-on: postgresql-contoured-63642
If I
heroku console
and check for the table Owner (Owner.new) it shows up with the correct properties ("first_name", "last_name"....). BUT, when I go to the site: https://peaceful-basin-47322.herokuapp.com/owners it only shows the table, with none of the instances of that model:
{
"owners": []
}
How to I migrate the instances of my model to Heroku?
Upvotes: 0
Views: 403
Reputation: 2290
I think the easiest way if you just want to populate the DB in heroku with your local DB contents is to do, on your terminal, from your app folder:
heroku pg:info
# this will show you something like:
# === HEROKU_POSTGRESQL_RED
# Plan Standard 0
# ...
# then with this you have the DB name HEROKU_POSTGRESQL_RED, do
heroku pg:push your_local_db_name_here HEROKU_POSTGRESQL_RED --app change_to_your_app_name
If your database is not empty it will ask you to do pg:reset
first. Remember you need a clean database to do this, if you want to mix your records from local into an existing DB then you need to do it in other ways.
Source: https://devcenter.heroku.com/articles/heroku-postgresql#pg-push-and-pg-pull
Upvotes: 0
Reputation: 2502
the data from your localhost is Different, with the data in your heroku. if you want it to be same you need dump your data from your localhost then import it to your heroku,
first dump your postgres localhost data
PGPASSWORD=mypassword pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump
then upload it to internet where heroku can download it, like amazon s3
heroku pg:backups:restore 'https://s3.amazonaws.com/me/items/3H0q/mydb.dump' DATABASE_URL
more you can read here https://devcenter.heroku.com/articles/heroku-postgres-import-export
rake db:migrate
only create the database tables, without the data, if you want to also create the data you can make it from seeds.rb
and then do rake db:seed
Upvotes: 2