【问题标题】:sqlite issue with herokuHeroku的sqlite问题
【发布时间】:2015-06-16 13:59:27
【问题描述】:

我在 Rails 项目中使用 sqlite gem,由于我必须将应用程序放在 Heroku 上,而 Heroku 不支持 sqlite,我将 pg gem 添加到我的 Gemfile。

 gem 'pg', '0.17.1'

但现在我无法在我的机器上本地运行该项目。

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

我收到了。

请帮忙。

【问题讨论】:

  • 请发布您的Gemfile
  • @Suraj:请参考我在此链接上的答案stackoverflow.com/questions/30846779/…
  • @Suraj:希望这对你有用。
  • 当我将其放入 Gemfile 时,您的答案中有一些语法问题

标签: ruby-on-rails sqlite heroku


【解决方案1】:

为数据库适配器指定了“sqlite3”,但未加载 gem。 将 gem 'sqlite3' 添加到您的 Gemfile 中(并确保其版本位于 ActiveRecord 要求的最小值)。

gem 'sqlite3', group: :development 添加到您的Gemfile 并执行bundle install

您还应该将pg gem 放在这样的生产组中,以避免在本地发生进一步的冲突

#Gemfile
group :production do
  gem 'pg', '0.17.1'
end

gem 'pg', '0.17.1', group: :production

gem 'sqlite3', group: :development

更新 #1

此外,您应该编辑您的database.yml 以像这样为developmentproduction 指定不同的适配器

#database.yml
development:
  adapter: sqlite3
  database: your_db
  username: your_username
  password: your_pass
  -----
  -----

production:
  adapter: postgresql
  database: your_production_db
  username: your_production_username
  password: your_production_pass
  ------
  ------

更新 #2

致命:用户“postgres”的对等身份验证失败

如果您设置了基于密码的身份验证,那么您需要执行以下步骤

1.为Ubuntu打开文件pg_hba.conf,它将位于/etc/postgresql/9.x/main并更改此行:

local   all             postgres                                peer

local   all             postgres                                md5

2.重启服务器

sudo service postgresql restart

3.登录psql并设置密码

psql -U postgres

ALTER USER postgres with password 'your-pass'; #as in your database.yml

【讨论】:

  • 致命:用户 "postgres" 的对等身份验证失败。遇到这个问题
  • 现在我得到密码验证失败的问题:/
  • @Suraj 你在database.yml文件中也设置了相同的密码
  • 它是一样的.. psql -U postgres 之后,当我输入相同的密码时它会询问我密码,我得到了上述问题..
【解决方案2】:

在您的 database.yml 中,将适配器:sqlite3 更改为适配器:postgresql

【讨论】:

    【解决方案3】:

    将您的 gemfile 中的 gem 'sqlite' 替换为 gem 'pg'

    删除你的Gemfile.lock 并运行bundle update

    然后,将以下内容粘贴到您的 config/database.yml

    development:
      adapter: postgresql
      encoding: unicode
      database: nameofyourapp_development
      pool: 5
      username: username
      password: password
    
    test:
      adapter: postgresql
      encoding: unicode
      database: discuss_test
      pool: 5
      username: username
      password: password
    

    根据您的配置替换用户名和密码。我的用户名是postgres,密码是1234

    Heroku 不需要您在 database.yml 中定义生产设置。推送应用后,它将自动配置。

    如果你收到FATAL: Peer authentication failed for user "postgres"

    问题出在您的/etc/postgresql/9.3/main/pg_hba.conf 文件中。这一行:

    local   all             postgres                                peer
    

    应该是

    local   all             postgres                                md5
    

    更改此/etc/init.d/postgresql reload 后,您需要重新加载您的 postgresql 服务

    【讨论】:

    • 致命:用户“postgres”的对等身份验证失败。
    猜你喜欢
    • 2011-08-17
    • 1970-01-01
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    • 2015-06-24
    • 1970-01-01
    • 2019-05-07
    相关资源
    最近更新 更多