PG::UndefinedColumn: ERROR: column sections.row_order does not exist
PG::UndefinedColumn: ERROR: column sections.row_order does not exist
<% @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 年 5 月 7 日开始为 10.0.2.2 获取“/courses/13”23:41:49 +0000
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" 上升限制 1
用户负载 (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" 上升限制 1 [["id", 2]]
Course Exists (0.4ms) SELECT 1 AS one FROM "courses" INNER JOIN "enrollments" ON "courses"."id" = "enrollments"."course_id" 其中 "enrollments"."user_id" = $1 AND "courses"."id" = 13 限制 1 [["user_id", 2]]
部分负载 (1.0ms) SELECT "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
在 layouts/application(57.0 毫秒)内呈现 courses/show.html.erb
在 240 毫秒内完成 500 个内部服务器错误
ActionView::Template::Error(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):
42:
43:
44:
45: <% @course.sections.rank(:row_order).每个做 |section| %>
46:
47:
48:
应用/视图/courses/show.html.erb:45:在`_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.9ms)
/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 rescues/layout (19.6ms)
在 2015 年 5 月 7 日开始为 10.0.2.2 获取“/courses/13”23:41:51 +0000
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" 上升限制 1
用户负载 (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" 上升限制 1 [["id", 2]]
课程存在(0.3 毫秒)SELECT 1 作为一个来自 "courses" INNER JOIN "enrollments" ON "courses"."id" = "enrollments"."course_id" 其中 "enrollments"."user_id" = $1 AND "courses"."id" = 13 限制 1 [["user_id", 2]]
部分负载 (0.7ms) SELECT "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
在 layouts/application(51.8 毫秒)内呈现 courses/show.html.erb
在 163 毫秒内完成 500 个内部服务器错误
ActionView::Template::Error(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):
42:
43:
44:
45: <% @course.sections.rank(:row_order).每个做 |section| %>
46:
47:
48:
应用/视图/courses/show.html.erb:45:在`_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.3ms)
/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 rescues/layout (21.3ms)
我的直接猜测是您忘记了 运行 迁移,并且从未添加该列。您可以通过查看 db/schema.rb 文件确认该列存在(并且迁移是 运行)。
我尝试重新启动服务器,添加新的迁移,并检查每个代码。受挫后,我就是这样做的..
耙子db:drop
耙子 db:create
耙子 db:migrate
所有数据都消失了。但是网站现在运行又正常了。
<% @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 年 5 月 7 日开始为 10.0.2.2 获取“/courses/13”23:41:49 +0000 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" 上升限制 1 用户负载 (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" 上升限制 1 [["id", 2]] Course Exists (0.4ms) SELECT 1 AS one FROM "courses" INNER JOIN "enrollments" ON "courses"."id" = "enrollments"."course_id" 其中 "enrollments"."user_id" = $1 AND "courses"."id" = 13 限制 1 [["user_id", 2]] 部分负载 (1.0ms) SELECT "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 在 layouts/application(57.0 毫秒)内呈现 courses/show.html.erb 在 240 毫秒内完成 500 个内部服务器错误
ActionView::Template::Error(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):
42:
43:
44:
45: <% @course.sections.rank(:row_order).每个做 |section| %>
46:
47:
48:
应用/视图/courses/show.html.erb:45:在`_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.9ms) /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 rescues/layout (19.6ms)
在 2015 年 5 月 7 日开始为 10.0.2.2 获取“/courses/13”23:41:51 +0000 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" 上升限制 1 用户负载 (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" 上升限制 1 [["id", 2]] 课程存在(0.3 毫秒)SELECT 1 作为一个来自 "courses" INNER JOIN "enrollments" ON "courses"."id" = "enrollments"."course_id" 其中 "enrollments"."user_id" = $1 AND "courses"."id" = 13 限制 1 [["user_id", 2]] 部分负载 (0.7ms) SELECT "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 在 layouts/application(51.8 毫秒)内呈现 courses/show.html.erb 在 163 毫秒内完成 500 个内部服务器错误
ActionView::Template::Error(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):
42:
43:
44:
45: <% @course.sections.rank(:row_order).每个做 |section| %>
46:
47:
48:
应用/视图/courses/show.html.erb:45:在`_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.3ms) /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 rescues/layout (21.3ms)
我的直接猜测是您忘记了 运行 迁移,并且从未添加该列。您可以通过查看 db/schema.rb 文件确认该列存在(并且迁移是 运行)。
我尝试重新启动服务器,添加新的迁移,并检查每个代码。受挫后,我就是这样做的..
耙子db:drop 耙子 db:create 耙子 db:migrate
所有数据都消失了。但是网站现在运行又正常了。