【问题标题】:PG::UndefinedColumn: ERROR: column sections.row_order does not existPG::UndefinedColumn: 错误: 列sections.row_order 不存在
【发布时间】:2015-07-18 18:12:26
【问题描述】:
<% @course.sections.rank(:row_order).each do |section| %>
    <br /><br />
        <div class="section">
            <h3>
                <%= section.title %>
            </h3>

我在部分中获得了该行顺序的未定义列。这是我的部分模型...

class Section < ActiveRecord::Base
belongs_to :course
has_many :lessons

include RankedModel
ranks :row_order, :with_same => :course_id
end

这是我的迁移。

class AlterSectionsAddRowOrder < ActiveRecord::Migration
  def change
    add_column :sections, :row_order, :integer
    add_index :sections, :row_order
  end
end

如果这有任何用处,这是我收到的错误消息。

在 2015-05-07 23:41:49 +0000 开始 GET "/courses/13" for 10.0.2.2 CoursesController 处理#show as HTML 参数:{"id"=>"13"} 课程负载 (0.5ms) SELECT "courses".* FROM "courses" WHERE "courses"."id" = $1 LIMIT 1 [["id", "13"]] 用户负载 (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 ORDER BY "users"."id" ASC LIMIT 1 用户负载 (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 2]] 课程存在(0.4 毫秒)从“课程”内部加入“注册”中选择 1 个“课程”。“id”=“注册”。“course_id”其中“注册”。“user_id”= $1 和“课程”。 "id" = 13 限制 1 [["user_id", 2]] 部分负载(1.0ms)选择“sections”。* FROM “sections” WHERE “sections”。“course_id” = $1 ORDER BY “sections”.“row_order” ASC [[“course_id”, 13]] PG::UndefinedColumn: 错误: 列sections.row_order 不存在 第 1 行:...ons" WHERE "sections"."course_id" = $1 ORDER BY "sections"... ^ : SELECT "sections".* FROM "sections" WHERE "sections"."course_id" = $1 ORDER BY "sections"."row_order" ASC 在布局/应用程序中渲染课程/show.html.erb (57.0ms) 在 240 毫秒内完成 500 个内部服务器错误

ActionView::Template::Error (PG::UndefinedColumn: ERROR: columnsections.row_order 不存在 第 1 行:...ons" WHERE "sections"."course_id" = $1 ORDER BY "sections"... ^ : SELECT "sections".* FROM "sections" WHERE "sections"."course_id" = $1 ORDER BY "sections"."row_order" ASC): 42: 43: 44: 45: 46:

47: 48: app/views/courses/show.html.erb:45:in `_app_views_courses_show_html_erb___522001594__582727588'

渲染/home/vagrant/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/_trace。 erb (2.0ms) 渲染 /home/vagrant/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.9小姐) 在救援中渲染 /home/vagrant/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/template_error.erb /布局(19.6 毫秒)

在 2015-05-07 23:41:51 +0000 开始 GET "/courses/13" for 10.0.2.2 CoursesController 处理#show as HTML 参数:{"id"=>"13"} 课程负载 (0.5ms) SELECT "courses".* FROM "courses" WHERE "courses"."id" = $1 LIMIT 1 [["id", "13"]] 用户负载 (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 ORDER BY "users"."id" ASC LIMIT 1 用户负载 (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 2]] 课程存在(0.3 毫秒)从“课程”中选择 1 个作为一个,在“课程”中加入“注册”。“id”=“注册”。“课程 ID”在哪里“注册”。“用户 ID”=1 美元和“课程”。 "id" = 13 限制 1 [["user_id", 2]] 部分负载(0.7ms)选择“sections”。* FROM “sections” WHERE “sections”。“course_id” = $1 ORDER BY “sections”.“row_order” ASC [[“course_id”, 13]] PG::UndefinedColumn: 错误: 列sections.row_order 不存在 第 1 行:...ons" WHERE "sections"."course_id" = $1 ORDER BY "sections"... ^ : SELECT "sections".* FROM "sections" WHERE "sections"."course_id" = $1 ORDER BY "sections"."row_order" ASC 在布局/应用程序中渲染课程/show.html.erb (51.8ms) 在 163 毫秒内完成 500 个内部服务器错误

ActionView::Template::Error (PG::UndefinedColumn: ERROR: columnsections.row_order 不存在 第 1 行:...ons" WHERE "sections"."course_id" = $1 ORDER BY "sections"... ^ : SELECT "sections".* FROM "sections" WHERE "sections"."course_id" = $1 ORDER BY "sections"."row_order" ASC): 42: 43: 44: 45: 46:

47: 48: app/views/courses/show.html.erb:45:in `_app_views_courses_show_html_erb___522001594__582727588'

渲染/home/vagrant/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/_trace。 erb (3.6ms) 渲染 /home/vagrant/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.3小姐) 在救援中渲染 /home/vagrant/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/template_error.erb /布局(21.3 毫秒)

【问题讨论】:

  • 您忘记运行迁移了吗?

标签: mysql ruby-on-rails ruby-on-rails-3 migration


【解决方案1】:

我尝试重新启动服务器、添加新迁移并检查每个代码。沮丧之后,我就是这样做的..

rake db:drop 耙分贝:创建 耙分贝:迁移

所有数据都消失了。但是现在网站又可以正常运行了。

【讨论】:

  • 奇怪 - 很高兴你把它修好了!不知何故,它混淆了。
【解决方案2】:

我的直接猜测是您忘记运行迁移并且该列从未添加。您可以通过查看您的 db/schema.rb 文件来确认该列是否存在(并且迁移已运行)。

【讨论】:

  • 嘿蒂姆。感谢您的回答。是的,迁移完成了。经过太多时间,我决定使用 rake db:drop,现在它可以工作了,但是数据都没有了。
猜你喜欢
  • 2015-10-13
  • 2013-12-15
  • 1970-01-01
  • 1970-01-01
  • 2016-06-01
  • 2020-01-16
  • 2016-07-11
  • 2022-11-28
  • 2015-11-24
相关资源
最近更新 更多