Heroku Deploy: URI::InvalidURIError: bad URI(is not URI?): ://user:pass@127.0.0.1/dbname
Heroku Deploy: URI::InvalidURIError: bad URI(is not URI?): ://user:pass@127.0.0.1/dbname
我有一个带有 Vue 前端和 rails 后端的项目。它只是一个非常简单的后端 API ,没有数据库或任何东西。它在本地运行良好,但现在我想将它部署到 Heroku 上。
但是,当我 运行 它时,我得到以下错误。
-----> Detecting rake tasks
!
! Could not detect rake tasks
! ensure you can run `$ bundle exec rake -P` against your app
! and using the production group of your Gemfile.
! rake aborted!
! URI::InvalidURIError: bad URI(is not URI?): ://user:pass@127.0.0.1/dbname
...
...
/activerecord-6.0.2.1/lib/active_record/railties/databases.rake
基于各种 SO posts/Heroku 文档,我已经尝试过:
bundle exec rake -P RAILS_ENV=production
- 一切正常
- 在 Gemfile 中添加
rake
依赖项
- 删除 Gemfile 中的
sqlite
依赖项
- 从 Gemfile.lock
中删除 BUNDLED WITH
但是还是一样的错误
我想这与我的数据库配置有关,但我的项目中没有任何数据库,所以这似乎是一项不必要的任务。我尝试从我的 Gemfile 中注释掉 railties,但它仍然作为其他 gem 的依赖项存在。当我在进行此更改后进行部署时,它仍然执行相同的任务但失败了。
Link 到 repo branch
而不是 require 'rails/all'
需要所有 Railties 包括 ActiveRecord 你需要明确地要求你想使用的 railties:
require File.expand_path('../boot', __FILE__)
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
# require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_mailbox/engine"
# require "action_text/engine"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
module Draw
class Application < Rails::Application
# You don't need this nonsense since you don't even have config/application.yml
# ENV.update YAML.load_file('config/application.yml')[Rails.env] rescue {}
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Do not swallow errors in after_commit/after_rollback callbacks.
# config.active_record.raise_in_transactional_callbacks = true
end
end
如果您不想使用 ActiveRecord,您可以去掉 /db
和 /config/database.yml
。
您也不需要在 Gemfile 中添加 have gem 'rake'
,因为 rails 无论如何都依赖于它。
需要从项目中完全删除对 ActiveRecord 的使用。作为, in a new app this can be done by doing rails new app_name --skip-active-record --api
, to do this for an existing project see
我有一个带有 Vue 前端和 rails 后端的项目。它只是一个非常简单的后端 API ,没有数据库或任何东西。它在本地运行良好,但现在我想将它部署到 Heroku 上。
但是,当我 运行 它时,我得到以下错误。
-----> Detecting rake tasks
!
! Could not detect rake tasks
! ensure you can run `$ bundle exec rake -P` against your app
! and using the production group of your Gemfile.
! rake aborted!
! URI::InvalidURIError: bad URI(is not URI?): ://user:pass@127.0.0.1/dbname
...
...
/activerecord-6.0.2.1/lib/active_record/railties/databases.rake
基于各种 SO posts/Heroku 文档,我已经尝试过:
bundle exec rake -P RAILS_ENV=production
- 一切正常- 在 Gemfile 中添加
rake
依赖项 - 删除 Gemfile 中的
sqlite
依赖项 - 从 Gemfile.lock 中删除 BUNDLED WITH
但是还是一样的错误
我想这与我的数据库配置有关,但我的项目中没有任何数据库,所以这似乎是一项不必要的任务。我尝试从我的 Gemfile 中注释掉 railties,但它仍然作为其他 gem 的依赖项存在。当我在进行此更改后进行部署时,它仍然执行相同的任务但失败了。
Link 到 repo branch
而不是 require 'rails/all'
需要所有 Railties 包括 ActiveRecord 你需要明确地要求你想使用的 railties:
require File.expand_path('../boot', __FILE__)
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
# require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_mailbox/engine"
# require "action_text/engine"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
module Draw
class Application < Rails::Application
# You don't need this nonsense since you don't even have config/application.yml
# ENV.update YAML.load_file('config/application.yml')[Rails.env] rescue {}
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Do not swallow errors in after_commit/after_rollback callbacks.
# config.active_record.raise_in_transactional_callbacks = true
end
end
如果您不想使用 ActiveRecord,您可以去掉 /db
和 /config/database.yml
。
您也不需要在 Gemfile 中添加 have gem 'rake'
,因为 rails 无论如何都依赖于它。
需要从项目中完全删除对 ActiveRecord 的使用。作为rails new app_name --skip-active-record --api
, to do this for an existing project see