我刚刚在这台机器上第一次安装了rbenv、ruby 2.2.3和rails 4.2.4.我已经启动了我的 rails 应用程序,没有更改任何代码,只是使用 rails new . 默认生成的文档,然后我使用 rails server 启动了服务器.
I've just installed rbenv, ruby 2.2.3 and rails 4.2.4 for the first time on this machine. I've started my rails application with no change to any of the code, just the default generated documents from using rails new ., I then started the server with rails server.
当点击 localhost:3000 我收到以下错误:
When hitting localhost:3000 I'm getting the following error:
为数据库适配器指定了 'postgresql',但未加载 gem.将 gem 'pg' 添加到您的 Gemfile(并确保其版本为 ActiveRecord 要求的最低版本)."
"Specified 'postgresql' for database adapter, but the gem is not loaded. Add gem 'pg' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord)."
我已经从以前的 Node 项目安装了 postgres,但我的 database.yml 仍然按照您对新应用程序的期望进行读取:
I've got postgres installed from a previous project with Node, but my database.yml still reads as you'd expect from a new application:
# 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 获取它以便停止此错误?
I don't really want to use Postgres at the moment, I'm just starting out and I'd rather keep things simple with SQLite3 for a bit. Does anyone know what may be going on and what I could do to get it using SQLite3 so that this error stops?
推荐答案问题在于,当您启动服务器时,它正在寻找环境变量 DATABASE_URL,它可能设置为 postgres,并且它优先于 database.yml 文件.您可以删除环境变量,它应该可以工作,或者您可以将其重置为 SQLite.
The problem is that when you start the server it is looking for environment variable DATABASE_URL which is probably set to postgres and this takes precedence over the database.yml file. You can delete the environment variable, and it should work, or you can reset it to SQLite.
更多推荐
新的 Rails 应用程序默认使用 Postgres 而不是 SQLite3
发布评论