如何在Rails迁移中添加一些插入? [英] How do I add some inserts in rails migration?
本文介绍了如何在Rails迁移中添加一些插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
创建表(通过迁移)后,我想直接插入一些条目.我该如何为此编写迁移?
After creating a table (by migration), I want to insert some entries directly. How must I write a migration for this?
谢谢
推荐答案
更新: 这是正确的答案: https://stackoverflow.com/a/2667747/7852
Update: This is the right answer: https://stackoverflow.com/a/2667747/7852
以下是红宝石api上的示例:
class AddSystemSettings < ActiveRecord::Migration
# create the table
def self.up
create_table :system_settings do |t|
t.string :name
t.string :label
t.text :value
t.string :type
t.integer :position
end
# populate the table
SystemSetting.create :name => "notice", :label => "Use notice?", :value => 1
end
def self.down
drop_table :system_settings
end
end
这篇关于如何在Rails迁移中添加一些插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文