gpt4 book ai didi

ruby-on-rails - 不使用 Postgres 时为 "pg is not part of the bundle. Add it to Gemfile"

转载 作者:太空宇宙 更新时间:2023-11-03 17:17:30 26 4
gpt4 key购买 nike

这是我的问题:

  • 我创建了一个新项目:rails new myapp
    Rails 应用程序默认配置为使用 SQLite3 数据库。

  • 我执行 bundle exec rake db:create。它工作并创建了 SQLite3 数据库。

  • 我尝试创建一个新模型(或任何其他与数据库相关的模型),但出现以下错误:

    /home/dinduks/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.3/lib/bundler/rubygems_integration.rb:147:in block in replace_gem': Please install the postgresql adapter:gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.) (LoadError)

  • 当我添加 Controller 和操作并尝试访问它时,出现此错误:

    ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)

    完整的堆栈跟踪可以在这里找到:https://gist.github.com/2717365
    WEBrick 服务器启动时显然没有任何提示。

我重新安装了 Rails,重新安装了 Ruby,使用了另一个 Ruby 版本,重新安装了 RVM... 并且一直出现同样的错误。

PostgreSQLpostgrespgpql 没有相关在我的代码中。一个字也没有。

我不想按照异常建议的去做。我想了解为什么会出现此错误并修复它。

那么:为什么 Rails 要求我安装一些 Postgres 的东西,而我不使用 Postgres

谢谢!

最佳答案

问题是 DATABASE_URL 环境变量。
当 ActiveRecord 找到 $DATABASE_URL 时,它会自动使用它的信息,并忽略 config/database.yml

感谢 NARKOZ 指出这一点。

(顺便说一下,我在发现 foreman 之前设置了这个环境变量,这是一个管理环境变量的好工具)

关于ruby-on-rails - 不使用 Postgres 时为 "pg is not part of the bundle. Add it to Gemfile",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10628282/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com