【发布时间】:2019-03-29 15:32:19
【问题描述】:
我正在关注本指南,https://devcenter.heroku.com/articles/getting-started-with-rails5。我取出“sqlite3”gem 并添加“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 'rails_12factor' 或将以下代码添加到我的 'config/environments/production.rb' 文件中
config/environments/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”]
【问题讨论】:
-
将“视频”重命名为“视频”。 Postgresql 对引用的名称区分大小写。更多详情:stackoverflow.com/questions/21796446/postgres-case-sensitivity
-
你能分享“视频”的迁移文件吗?
-
这是一个区分大小写的问题,谢谢!如果您想将此评论作为答案,我很乐意将其标记为正确答案。