宝石文件:
source 'https://rubygems.org'
gem 'rails', '5.0.1'
gem 'bcrypt', '3.1.11'
gem 'puma', '3.4.0'
gem 'sass-rails', '5.0.6'
gem 'uglifier', '3.0.0'
gem 'coffee-rails', '4.2.1'
gem 'jquery-rails', '4.1.1'
gem 'turbolinks', '5.0.1'
gem 'jbuilder', '2.4.1'
gem 'bootstrap-sass', '3.3.6'
gem 'unicorn'
group :development, :test do
gem 'sqlite3', '1.3.12'
gem 'byebug', '9.0.0', platform: :mri
end
group :development do
gem 'web-console', '3.1.1'
gem 'listen', '3.0.8'
gem 'spring', '1.7.2'
gem 'spring-watcher-listen', '2.0.0'
end
group :test do
gem 'rails-controller-testing', '0.1.1'
gem 'minitest-reporters', '1.1.9'
gem 'guard', '2.13.0'
gem 'guard-minitest', '2.4.4'
end
group :production do
gem 'pg', '0.18.4'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
database.yml中:
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
运行rake db:migrate时,迁移失败。 尝试使用RAILS_ENV =开发将环境变量设置为开发仍然失败。我在生产中使用postgres,因为heroku提供了postgres.Both给出了gem文件和database.yml。
编辑: 我尝试将repo克隆到另一台机器上并尝试它工作正常。
答案 0 :(得分:0)
执行此操作时:
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
然后这个:
production:
<<: *default
database: db/production.sqlite3
然后,生产中的适配器为sqlite3
。看看你如何设置默认值,然后没有在生产中设置它?
此外,这一点:
production:
...
database: db/production.sqlite3 << right here
好像它会让你心痛。
您自然会意识到,不推荐在开发中使用sqlite,在生产中使用postgresql。它在Heroku网站上如此说。因为,嗯,你现在将会遇到各种各样的噩梦。 (在Heroku网站和Innerwebs周围有更多的技术解释。阅读它们。这对灵魂有益。)
除非你喜欢那种东西。
*编辑*
抱歉,我的行动速度太快了。在运行rake db:migrate
时,您似乎在本地遇到了问题?
无论如何,在开发和生产中使用不同的DB仍然不是一个好主意。
答案 1 :(得分:0)
尝试显式设置数据库配置以进行开发。看起来database.yml没有正确对齐。
production:
adapter: postgresql
encoding: utf8
database: your_db
host: 127.0.0.1
pool: 5
username: your_db_username
password: your_db_password