我在ruby on rails教程的第9章上,我在最后一刻遇到了问题。一切都在我的页面上正常工作,但不在heroku上。 以下是他说的步骤:
$ git push heroku
$ heroku pg:reset DATABASE
$ heroku run rake db:migrate
$ heroku run rake db:seed
$ heroku restart
当我运行rake db:seed
Running rake db:seed on radiant-peak-3596... up, run.3507
ActiveRecord::SchemaMigration Load (2.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
(4.6ms) BEGIN
User Exists (8.1ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('example@hotmail.com') LIMIT 1
(3.8ms) ROLLBACK
rake aborted!
ActiveRecord::RecordInvalid: Validation failed: Email has already been taken
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/validations.rb:79:in `raise_record_invalid'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/validations.rb:43:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/transactions.rb:291:in `block in save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/transactions.rb:347:in `block in with_transaction_returning_status'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/transactions.rb:220:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/transactions.rb:344:in `with_transaction_returning_status'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/transactions.rb:291:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/persistence.rb:51:in `create!'
/app/db/seeds.rb:9:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `load'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `block in load'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:240:in `load_dependency'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `load'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.2/lib/rails/engine.rb:547:in `load_seed'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/tasks/database_tasks.rb:250:in `load_seed'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/railties/databases.rake:180:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)
seed.rb
User.create!(name: "example user",
email: "example@hotmail.com",
password: "foobar",
password_confirmation: "foobar",
admin: true )
99.times do |n|
name = Faker::Name.name
email = "example-#{n+1}@aol.org"
password = "password"
User.create!(name: name,
email: email,
password: password,
password_confirmation: password)
end
我已经安装了宝石并且运行完美,但是heroku是另一种情况。
谢谢!
答案 0 :(得分:0)
确保数据库正确重置。似乎在运行rake db:seed
时,它正在对已经创建用户的数据库执行此操作,这会导致验证错误。
答案 1 :(得分:0)
你希望艺术代理人能够拥挤你所申请的每所大学 - 在你可能拥有的众多司法管辖区内 - 加上你拥有关于你自己的综合体,沉淀在你所在的学院的传播敏锐中说话的同时你把这个ancillarys归来了。 windows 8.1 key