poponga
poponga

Reputation: 45

heroku run rake db:seed is failed

I made an web application on heroku and tried to add admin user by heroku rake db:seed. I can make users in an application, but I do not know how to code well in seeds.rb. heroku run rake db:migrate was successful. As of now, I am not able to log in with admin and adminpw.

timestamp_create_user.rb

class CreateUsers < ActiveRecord::Migration[5.2]
  def change
    create_table :users do |t|
      t.string :userid
      t.string :email
      t.string :password_digest

      t.timestamps
    end
  end
end

seeds.rb

User.create!(
   userid: 'admin',
   email: '[email protected]',
   password: 'adminpw',
   passwor_confirmation: 'adminpw',
   admin: true
)

heroku logs

, [2019-02-27T02:46:45.074640 #4] DEBUG -- : (1.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC

Upvotes: 0

Views: 920

Answers (1)

Kamal Panhwar
Kamal Panhwar

Reputation: 2399

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: '[email protected]',
   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.

Upvotes: 2

Related Questions