Mysql2::错误:无法在 heroku 推送时连接到"127.0.0.1"上的 MySQL 服务器



当我做git推送heroku master时,它在rake资产预编译时失败,并且出现错误Mysql2::Error: Can't connect to MySQL server on '127.0.0.1' heroku

我已经知道的由于我使用的是 Rails 4,因此肯定config.assets.initialize_on_precompile = false不在图片中,因为不再需要。

heroku labs:enable user-env-compile Heroku 不再支持此功能。

在网上做研究后,我了解到解决方案可能在这里英雄构建包但是我不明白如何运行这些命令。我一直在bash: bin/compile: No such file or directory

如何解决此问题?我正在使用Rails 4.2.5,Ruby 2.3.0,并且Db在本地是Mysql。提前谢谢你。

数据库.yml

default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: password
host: localhost
development:
<<: *default
database: respect_development
test:
<<: *default
database: respect_test
production:
   <<: *default
database: respect_production
username: respect
password: <%= ENV['RESPECT_DATABASE_PASSWORD'] %>

听起来您的database.yml配置为使用本地数据库(127.0.0.1),即使在Heroku上也是如此。你database.yml里有什么?我会从 git 中删除该文件并检查您的 Heroku 配置变量是否有DATABASE_URL.您应该在 Heroku 上看到对数据库的引用,而不是 127.0.0.1

我只需要在本地预编译资产rake assets:precompile,然后将其推送git push heroku master在我的环境/生产中。

config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?

我也把它添加到我的宝石文件中

group :production do
   gem 'rails_12factor'
  end

相关内容

最新更新