Rails3 Mysql2 :: Error:未知列-ActiveRecord :: StatementInvalid [英] Rails3 Mysql2::Error: Unknown column - ActiveRecord::StatementInvalid

查看:81
本文介绍了Rails3 Mysql2 :: Error:未知列-ActiveRecord :: StatementInvalid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是在此级别上使用Rails的数据库的新手,我花了好几个小时,但尚未找到解决此特定问题的解决方案.

I'm new to working with databases in Rails at this level, and I've looked for several hours but haven't found a solution to this specific problem.

版本: Rails 3.2.9,Ruby 1.9.3,MySQL 5.5.28(mysql2 gem 2.9.0),Mac OS 10.7.5

错误:

ActiveRecord::StatementInvalid in Action_figures#list

Mysql2::Error: Unknown column 'action_figures.position' in 'order clause': SELECT `action_figures`.* FROM `action_figures`  ORDER BY action_figures.position ASC

提取的来源(第14行附近):[list.html.erb]

Extracted source (around line #14): [list.html.erb]

11:       <th>Visible</th>
12:       <th>Actions</th>
13:     </tr>
14:     <% @action_figures.each do |action_figure| %>
15:     <tr>
16:       <td><%= action_figure.position %></td>
17:       <td><%= action_figure.name %></td>

我生成了ActionFigures模型和控制器,但稍后在迁移文件中指定了:position,:name等:

class CreateActionFigures < ActiveRecord::Migration
  def change
    create_table :action_figures do |t|
      t.string "name"
      t.integer "position"
      t.boolean "visible", :default => false
      t.timestamps
    end
  end
end

这在模型中:

class ActionFigure < ActiveRecord::Base
  has_many :pages
  attr_accessible :name, :position, :visible
end

我已经运行了rake db:migrate次,停止并重新启动了服务器,关闭并重新打开了终端,以确保不是那些东西,但是当我这样做时:

I've run rake db:migrate several times already, stopped and restarted the server, closed and reopened Terminal just to be sure it wasn't those things, but when I do:

mysql> SHOW FIELDS FROM action_figures;

我得到下表:

+------------+----------+------+-----+---------+----------------+
| Field      | Type     | Null | Key | Default | Extra          |
+------------+----------+------+-----+---------+----------------+
| id         | int(11)  | NO   | PRI | NULL    | auto_increment |
| created_at | datetime | NO   |     | NULL    |                |
| updated_at | datetime | NO   |     | NULL    |                |
+------------+----------+------+-----+---------+----------------+

问题:

  1. 为什么表中未显示:name,:position和:visible?
  2. 如何立即添加它们?
  1. Why are :name, :position, and :visible not showing up in the table?
  2. How to I add them now?

推荐答案

您是否添加了表...运行迁移..然后编辑迁移文件以添加位置和可见属性?如果是这样,则需要添加新的迁移(或重新运行上一个迁移)

Did you add the table ... run the migrations .. and then edit the migration file to add position and visible attributes? If so, you'll need to add a new migration (or rerun the last migration)

尝试一下;

rails g migration add_position_to_action_figures position:integer visible:boolean

bundle exec rake db:migrate

这篇关于Rails3 Mysql2 :: Error:未知列-ActiveRecord :: StatementInvalid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆