gpt4 book ai didi

ruby-on-rails - Fresh Rails 应用程序默认使用 Postgres 而不是 SQLite3

转载 作者:数据小太阳 更新时间:2023-10-29 07:47:43 27 4
gpt4 key购买 nike

我刚刚在这台机器上第一次安装了 rbenv、ruby 2.2.3 和 rails 4.2.4。我启动了我的 Rails 应用程序,没有更改任何代码,只是使用 rails new . 生成的默认文档,然后我使用 rails server 启动了服务器。

当点击 http://localhost:3000 时,出现以下错误:

“为数据库适配器指定了‘postgresql’,但未加载 gem。将 gem 'pg' 添加到您的 Gemfile(并确保其版本为 ActiveRecord 要求的最低版本)。”

我已经从以前的 Node 项目中安装了 postgres,但是我的 database.yml 仍然像您对新应用程序的期望那样读取:

# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
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

我现在真的不想使用 Postgres,我才刚刚开始,我宁愿使用 SQLite3 让事情简单一些。有谁知道可能发生了什么以及我可以做些什么来使用 SQLite3 来获取它以便停止此错误?

最佳答案

还有另一种解决方案,适用于那些实际需要保留 DATABASE_URL 环境变量而不影响 Rails 的人(比如我)。您可以使用 url 子键:

development:
<<: *default
url: sqlite3:db/development.sqlite3

这已记录在案 here .

关于ruby-on-rails - Fresh Rails 应用程序默认使用 Postgres 而不是 SQLite3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32287768/

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