×Welcome to Q&A for professional and enthusiast programmers — check out the FAQ!

After deploying an app of Heroku I am having trouble getting the database populated with some of the data I need there. I ran heroku rake db:populate and it did create the initial admin user, but failed to put the rest of the data in.

I am populating the database with files from my local disk. I suspect the problem is caused because it sees nothing in the directory listed in the sample_data.rake file, as it in on my hdd and not the server. How can I get around this?

I figure that I have to either host all the files and change the directory to the servers directory, or find a way around this. I would guess there is an easy way to move the database from my computer to heroku? I'm obviously pretty new to this.


link|improve this question

71% accept rate
Not really an answer but have you considering using seed data instead of loading data from your local disk ? See file db/seeds.rb and task rake db:seed – Adrien Coquio Jun 16 '11 at 7:40

2 Answers

up vote 2 down vote accepted

If you have a clean local database (i.e. just the good stuff, no silly testing data), then you could try heroku db:push:

db:push [<database_url>] # push a local database into the app's remote database

And please remember to develop on PostgreSQL if you're going to use the Heroku shared or dedicated databases, using the same database and version (version 8.3 for shared, 9.0 for dedicated) in both your development and production environments will save you much pain, suffering, and confusion.


link|improve this answer
What if you only want to upload a single table, or add data to an existing table? – B Seven Aug 20 '11 at 14:10
@B Seven: heroku help db:push will tell you how. – mu is too short Aug 20 '11 at 20:17

I setup the development db, and push it to Heroku.

rake db:reset
rake db
heroku rake db

If you are using the default PostgreSQL, another option is

heroku pg:reset
heroku rake db

I use the following in the seed.rb file:

require 'pathname'
RailsRoot = Pathname.new(RAILS_ROOT).expand_path

print "Loading data..."
= File.read (RailsRoot + "db/data-file.csv")
link|improve this answer

Your Answer

required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.