将Postgresql添加到现有的Rails项目中

问题描述 投票:0回答:1

我正在按照这个指南,https://devcenter.heroku.com/articles/getting-started-with-rails5。我拿出'sqlite3'宝石并添加'pg',然后运行bundle install。然后我将config / database.yml文件更改为如下所示

config / database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: myapp5_development

test:
  <<: *default
  database: myapp5_test

production:
  <<: *default
  database: myapp5_production
  username: myapp5
  password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>

对于下一部分,指南给了我两个选择,我尝试了两个。安装此gem'trail_12factor'或将以下代码添加到我的'config / environments / production.rb'文件中

配置/环境/ production.rb

config.public_file_server.enabled =     ENV['RAILS_SERVE_STATIC_FILES'].present?

if ENV["RAILS_LOG_TO_STDOUT"].present?
  logger           = ActiveSupport::Logger.new(STDOUT)
  logger.formatter = config.log_formatter
  config.logger = ActiveSupport::TaggedLogging.new(logger)
end

然后,如果我运行rake db:create后跟rake db:migrate,它会给我错误,所以我运行rake db:reset,这样就可以运行迁移。如果我启动我的网站,我会收到错误

PG::UndefinedTable: ERROR:  relation "videos" does not exist
LINE 1: SELECT  "videos".* FROM "videos" ORDER BY "videos"."title" A...
                            ^
: SELECT  "videos".* FROM "videos" ORDER BY "videos"."title" ASC LIMIT $1 OFFSET $2
Extracted source (around line #2):

<div class="container">
<% @videos.each do |x| %>
<p> <div class="child">  
  <video controls width="310" height="230" src="<%= x.file %>"></video>
    <p> <%= x.title %> </p>

当我通过ActiveRecord :: Base.connection.tables查看我的表时,我发现视频存在。

[“视频”,“ipaddresstrackers”,“用户”,“投票”,“schema_migrations”,“ar_internal_metadata”]

ruby-on-rails postgresql
1个回答
1
投票

将“视频”表重命名为“视频”。

在PostgreSQL中,不带引号的名称不区分大小写。因此,SELECT * FROM videosSELECT * FROM ViDeOs是等价的。

但是,引用的名称区分大小写。 SELECT * FROM "videos"不等同于SELECT * FROM "Videos"

更多细节here

© www.soinside.com 2019 - 2024. All rights reserved.