我有简单的 Rails 2 作曲家应用程序。我可以很好地在本地对应用程序进行 rake 迁移和播种,并且设置了种子文件中的管理员用户。但是,数据库不会在 Heroku 上播种。我收到以下错误(运行时带有跟踪 - heroku run rake db:setup --trace ):
** Execute db:abort_if_pending_migrations
ROLES
rake aborted!
can't convert nil into String
这是我的代码:
种子.rb
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
# Environment variables (ENV['...']) are set in the file config/application.yml.
# See http://railsapps.github.io/rails-environment-variables.html
puts 'ROLES'
YAML.load(ENV['ROLES']).each do |role|
Role.find_or_create_by_name({ :name => role }, :without_protection => true)
puts 'role: ' << role
end
puts 'DEFAULT USERS'
user = User.find_or_create_by_email :name => ENV['ADMIN_NAME'].dup, :email => ENV['ADMIN_EMAIL'].dup, :password => ENV['ADMIN_PASSWORD'].dup, :password_confirmation => ENV['ADMIN_PASSWORD'].dup
puts 'user: ' << user.name
user.add_role :admin
user.save!
应用程序.yml
GMAIL_USERNAME: Your_Username
GMAIL_PASSWORD: Your_Password
ADMIN_NAME: First User
ADMIN_EMAIL: user@example.com
ADMIN_PASSWORD: changeme
ROLES: [admin, user]
我对rails相当陌生。该应用程序最初确实是种子,但我已经进行了一些迁移并回滚了一次。
非常感谢任何帮助。