PG :: UndefinedColumn:错误:列sections.row_order不存在

时间:2015-05-07 23:43:35

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

<% @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

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

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

ActionView :: Template :: Error(PG :: UndefinedColumn:错误:列sections.row_order不存在 第1行:... ons&#34;在哪里&#34;部分&#34;。&#34; course_id&#34; = $ 1 ORDER BY&#34;部分&#34; ...                                                              ^ :SELECT&#34; sections&#34;。* FROM&#34; sections&#34;在哪里&#34;部分&#34;。&#34; course_id&#34; = $ 1 ORDER BY&#34;部分&#34;。&#34; row_order&#34; ASC):     42:     43:     44:     45:&lt;%@ course.sections.rank(:row_order).each do | section | %GT;     46:

    47:     48:   app / views / courses / show.html.erb:45:在`_app_views_courses_show_html_erb ___ 522001594__582727588&#39;

呈现/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 / layout(19.6ms)

开始GET&#34; / courses / 13&#34;对于10.0.2.2在2015-05-07 23:41:51 +0000 由CoursesController处理#show as HTML   参数:{&#34; id&#34; =&gt;&#34; 13&#34;}   课程负荷(0.5ms)SELECT&#34;课程&#34;。* FROM&#34;课程&#34;在哪里&#34;课程&#34;。&#34; id&#34; = $ 1 LIMIT 1 [[&#34; id&#34;,&#34; 13&#34;]]   用户负载(0.6ms)SELECT&#34;用户&#34;。* FROM&#34;用户&#34;用户&#34;。&#34; id&#34; = 2 ORDER BY&#34;用户&#34;。&#34; id&#34; ASC限制1   用户负载(0.5ms)SELECT&#34;用户&#34;。* FROM&#34;用户&#34;用户&#34;。&#34; id&#34; = $ 1 ORDER BY&#34;用户&#34;。&#34; id&#34; ASC限制1 [[&#34; id&#34;,2]]   课程存在(0.3ms)选择1作为一个FROM&#34;课程&#34; INNER JOIN&#34;注册&#34; ON&#34;课程&#34;。&#34; id&#34; =&#34;注册&#34;。&#34; course_id&#34;在哪里&#34;注册&#34;。&#34; user_id&#34; = $ 1 AND&#34;课程&#34;。&#34; id&#34; = 13 LIMIT 1 [[&#34; user_id&#34;,2]]   部分加载(0.7ms)SELECT&#34;部分&#34;。* FROM&#34;部分&#34;在哪里&#34;部分&#34;。&#34; course_id&#34; = $ 1 ORDER BY&#34;部分&#34;。&#34; row_order&#34; ASC [[&#34; course_id&#34;,13]] PG :: UndefinedColumn:错误:列sections.row_order不存在 第1行:... ons&#34;在哪里&#34;部分&#34;。&#34; course_id&#34; = $ 1 ORDER BY&#34;部分&#34; ...                                                              ^ :SELECT&#34; sections&#34;。* FROM&#34; sections&#34;在哪里&#34;部分&#34;。&#34; course_id&#34; = $ 1 ORDER BY&#34;部分&#34;。&#34; row_order&#34; ASC   在布局/应用程序中呈现课程/ show.html.erb(51.8ms) 在163毫​​秒内完成500内部服务器错误

ActionView :: Template :: Error(PG :: UndefinedColumn:错误:列sections.row_order不存在 第1行:... ons&#34;在哪里&#34;部分&#34;。&#34; course_id&#34; = $ 1 ORDER BY&#34;部分&#34; ...                                                              ^ :SELECT&#34; sections&#34;。* FROM&#34; sections&#34;在哪里&#34;部分&#34;。&#34; course_id&#34; = $ 1 ORDER BY&#34;部分&#34;。&#34; row_order&#34; ASC):     42:     43:     44:     45:&lt;%@ course.sections.rank(:row_order).each do | section | %GT;     46:

    47:     48:   app / views / courses / show.html.erb:45:在`_app_views_courses_show_html_erb ___ 522001594__582727588&#39;

呈现/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 / layout(21.3ms)

2 个答案:

答案 0 :(得分:2)

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

rake db:drop rake db:create rake db:migrate

所有数据都消失了。但该网站现在再次正常运行。

答案 1 :(得分:0)

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