我正在尝试为仅用作枚举的简单表创建迁移。所以我想立即用它的值填充表格。我试过如下:在迁移中填充Rails类
class CreateUserTypes < ActiveRecord::Migration
def self.up
create_table :user_types do |t|
t.column :type, :string
t.timestamps
end
end
def self.down
drop_table :user_types
end
UserType.create :type => "System administrator"
UserType.create :type => "Simulation controller"
end
,但我得到这个错误:
rake aborted!
An error has occurred, all later migrations canceled:
Could not find table 'user_types'
我是继Rails wiki和预期它的工作。
谢谢。但是你的建议似乎并不奏效。那么,我看不到弦。
sqlite> select * from user_types;
1||2009-02-08 12:00:56|2009-02-08 12:00:56
2||2009-02-08 12:00:57|2009-02-08 12:00:57
下一个问题:什么我必须这样做耙分贝:迁移在更改迁移文件后,将更新数据库。耙子看起来不像C那样工作。 – alamodey 2009-02-08 11:08:24
每个迁移文件都按顺序运行。如果您更改了迁移文件,则应该回滚到该版本并重新运行。或者,您可以编写进一步的迁移文件,以便在原始文件上进行所需的更改。 – DanSingerman 2009-02-08 11:25:33