Heroku: How to Push Seeds.Rb to Existing Rails App

Heroku: How to push seeds.rb to existing rails app?

If you push the app to heroku, you can seed the database with the following command.

heroku run rake db:seed

Cannot seed data in production using heroku

seeds.rb should be in the repository in order for rails to seed it. If there is no seeds.rb, rails doesn't complain that the file is missing, instead it just completes the rake db:seed task with out any error.

So make sure you remove the seeds.rb from the .gitignore, add it to the git with git add --force db/seeds.rb and git push it to the repository.

heroku run rake db:seed is failed

You can diagnose errors by doing the following. Run rails c

Now add the following line in prompt of rails c

u = User.create!(
userid: 'admin',
email: 'admin@testing.com',
password: 'adminpw',
passwor_confirmation: 'adminpw',
admin: true
)

Now write the following to see what is the error or is it valid?

u.valid?

If you get false, that means you have errors in your information or validation is not being fullfiled. To know exactly what is issue use following command

u.errors.messages

Now you will knwo what is error and you can modify it to get proper seeding of data.

Heroku run rake db:seed gives expecting keyword_end

The "expected keyword_end" error means you have a syntax error in the specified file. You'll see this a lot, especially in your test suite; get cozy with it.

Go through the file with a fine-tooth comb and mentally match up each { with its } and each do with its end. Usually you discover that one of these is mismatched.

If you can't find the mismatch, comment out your entire seed file and run rake db:seed again. The error should not appear. Then progressively uncomment each section of the file until you figure out where the error comes from.

This is tedious but it works.



Related Topics



Leave a reply



Submit