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
Ruby Get Time in Given Timezone
What Are the Advantages of Mocha Over Rspec's Built in Mocking Framework
Escape Double and Single Backslashes in a String in Ruby
Get Title, Content via Link in Rails
Detect Browser Language in Rails
Deleting While Iterating in Ruby
How to Save Dates in Local Timezone to Db with Rails3
How to Uppercase Each Element of an Array
What Is the Activemodel Method Attribute "_Was" Used For
How to Debug Ruby on Rails in Eclipse Aptana Plugin
Make: /Usr/Bin/Mkdir: Command Not Found During 'Gem Install Nokogiri' in Ubuntu 20.04
How to Route Controllers Without Crud Actions
Run Delayed Jobs and Sidekiq at the Same Time
What Are the Conventional Gem Paths for Ruby Under Os X 10.5
Extract Fast Fourier Transform Data from File
Ruby: Titleize: How to Ignore Smaller Words Like 'And', 'The', 'Or, etc
Executing Shell Command in Background from Ruby with Proper Argument Escaping