我是在这个级别使用 Rails 中的数据库的新手,我已经寻找了几个小时,但还没有找到解决这个特定问题的方法。
版本: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]
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
了几次,停止并重新启动服务器,关闭并重新打开终端只是为了确保它不是那些东西,但是当我这样做时:
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 | |
+------------+----------+------+-----+---------+----------------+
问题:
- 为什么 :name、:position 和 :visible 没有出现在表格中?
- 我现在如何添加它们?