【问题标题】:heroku deploy error in RoR(Github deploy) what should I do with postgresql error?RoR(Github部署)中的heroku部署错误我应该如何处理postgresql错误?
【发布时间】:2017-11-07 00:49:55
【问题描述】:

我正在将小应用程序从 C9 部署到 github,然后再部署到 Heroku! 在 heroku 部署仪表板中,它说它已部署,但是当我打开应用程序时,它只会给我错误消息。 所以我搜索了很多 Stackoverflow 答案,并按照 Heroku 网站(https://devcenter.heroku.com/articles/sqlite3)的指示删除 sqlite3 并安装 gem pg。

我确实将 gem 'sqlite3' 替换为 gem 'pg' 并进行了 'bundle install',然后

它说我需要转换我的 config/database.yml 文件,所以我像这样替换它:

development:
  adapter: postgresql
  database: my_database_development
  pool: 5
  timeout: 5000
test:
  adapter: postgresql
  database: my_database_test
  pool: 5
  timeout: 5000

production:
  adapter: postgresql
  database: my_database_production
  pool: 5
  timeout: 5000

然后当我回到 c9 bash 并输入“rake db:create”时, 它告诉我

**rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  database "my_database_development" does not exist**

这个错误。

有人说 'bundle exec rake db:setup' 会起作用,所以我做了,然后它显示了

**Couldn't create database for {"adapter"=>"postgresql", "database"=>"my_database_test", "pool"=>5, "timeout"=>5000}
/home/ubuntu/workspace/db/schema.rb doesn't exist yet. Run `rake db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter /home/ubuntu/workspace/config/application.rb to limit the frameworks that will be loaded.**

我不知道如何对此消息做出反应....当我输入“rake db:migrate”时,它再次显示。

rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  database "my_database_development" does not exist

我没有使用数据库,所以也许我可以在 'config/application.rb' 文件上尝试一些东西,但我应该怎么做呢?

【问题讨论】:

  • rake db:create 然后rake db:migrate
  • 我已经完成了 'rake db:create',但没有像我写的那样工作......
  • rake db:reset
  • rake db:setup 一样的错误加上PG::InvalidParameterValue: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII) HINT: Use the same encoding as in the template database, or use template0 as template. : CREATE DATABASE "my_database_development" ENCODING = 'utf8'

标签: ruby-on-rails heroku github sqlite


【解决方案1】:

您可以手动创建数据库的解决方案之一,这很容易解决

【讨论】:

    【解决方案2】:

    没有必要更改您的 developmenttest 数据库,它们仍然可以使用 sqlite3,因此您的 C9 实例将继续工作。

    (尽管在所有环境中使用一致的适配器有一些优势)

    如果这只是一个爱好练习,我很想保留 sqlite3 进行开发和测试。

    此外,Heroku 将 database.yml 替换为自己的版本,因此您不需要 database.yml 中的生产节

    您确实需要pg gem,但您可以指定它仅在生产中加载,您可以指定sqlite3 gem 仅在开发和测试中加载。在您的 Gemfile 中执行此操作,然后打包。

    group :development, :test do
      gem 'sqlite3'
    end
    
    group :production do
      gem 'pg'
    end
    

    如果您想在您的 C9 实例中使用 PostgreSQL,您必须安装 PostgreSQL(数据库,而不仅仅是适配器)。这不是一个简单的过程。

    这个 wiki 解释了如何安装它。

    https://wiki.postgresql.org/wiki/Detailed_installation_guides

    【讨论】:

    • 我用你的答案解决了这个问题,并没有通过 Github 用新的 git 部署新的 Heroku。我不需要数据库。谢谢!
    • 太好了。如果我的回答有帮助,请随时点赞或接受。
    猜你喜欢
    • 1970-01-01
    • 2018-08-18
    • 2020-07-29
    • 2011-03-25
    • 2021-05-10
    • 1970-01-01
    • 2016-01-05
    相关资源
    最近更新 更多