Rails Heroku Database Population Database

After deploying the Heroku application, I had a problem filling the database with some data that I need. I ran heroku rake db: populate and it created the initial admin user, but was unable to put the rest of the data.

I populate the database with files from my local drive. I suspect that the problem is caused by the fact that she does not see anything in the directory specified in the sample_data.rake file, as on my hdd, and not on the server. How can I get around this?

I believe that I need to either place all the files, or change the directory to the server directory, or find a way around this. I would suggest that there is an easy way to move the database from my computer to the geroku? I am obviously pretty new to this.

Thanks!

+6
source share
3 answers

If you have a clean local database (i.e. only good stuff, not stupid test data), you can try heroku db:push :

db:push [<database_url>] # push the local database to the remote application database

And please do not forget to develop PostgreSQL if you intend to use Heroku shared or dedicated databases using the same database and version (version 8.3 for shared access, 9.0 for dedicated) in both development and production environments will save you a lot of pain, suffering and confusion.

Literature:

+9
source
Teams

heroku changed. now it should be:

 heroku run rake db:push heroku pg:reset DATABASE heroku run rake db:seed 

Also, data from the local database can be uploaded to heroku by setting the gem label and clicking data from the local PostgreSQL db.

 gem install taps heroku db:push 
+12
source

I set up db development and push it to Heroku.

 rake db:reset rake db:seed heroku rake db:push 

If you are using PostgreSQL by default, another option

 heroku pg:reset heroku rake db:seed 

I use the following in seed.rb file:

 require 'pathname' RailsRoot = Pathname.new(RAILS_ROOT).expand_path print "Loading data..." fileData = File.read (RailsRoot + "db/data-file.csv") 
+3
source

Source: https://habr.com/ru/post/890657/


All Articles