I am working with a Ruby on Rails application that I clone from Git and uses a Postgres database. I successfully clone the repository to my local area and bring up the website, but all of my database tables are empty. What do I need to do to transfer the data in the tables to my local build? (I am new to Ruby on Rails, PostgreSQL AND Git!)
You can seed the basic data your application depends from the seeds.rb using the rake task
RAILS_ENV=development rake db:seed
You can backup and restore the data from another remote /local database(like production database / staging database) using the utilities pg_dump
and psql
from postgres
Step1: Backup
pg_dump
utility can be used to back up the database into the SQL commands and output to the given file. The below will create a file dump.sql on the given directory with the series of SQL commands.
pg_dump -h host_name -U user_name -d remote_database_name > /path/to/backup/file/dump.sql
Step2: Restore
Then restore the data from the file to your local database using:
psql -U user_name -d local_data_base_name < /path/to/backuo/file/dump.sql
Please be careful on using the production database backup (if any) in your local, since there may be real users and we might mistakenly trigger emails / SMS.,etc to these users.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.