创建表(通过迁移)后,我想直接插入一些条目.我必须如何为此编写迁移?

谢谢

推荐答案

Update:


下面是一个来自ruby on rails 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

Ruby-on-rails相关问答推荐

将日期时间转换为月、日和年?

如何在 Ruby on Rails 中创建一个锚点并重定向到这个特定的锚点

设计:手动加密密码并直接存储

无法连接 localhost:3000 ruby​​ on rails in vagrant

如何在 rails 中指定和验证枚举?

如何添加到序列化数组

URL中的Rails点而不是斜杠

Rails 错误:无法批量分配受保护的属性

在 factory_girl 中填充与 children 的关联

rmagick 和 OS X Lion

使 rails 控制台输出更漂亮一点

在范围内传递参数

Rails 3.1 中的 Rails.cache 错误 - TypeError: can't dump hash with default proc

如何一次显示一条 Ruby on Rails 表单验证错误消息?

在 Rails 中命名布尔列

rake db:回滚不起作用?

ActiveRecord 查找以

为什么不对 Rspec + Selenium 使用共享的 ActiveRecord 连接?

ActiveModel::MissingAttributeError:无法使用 FactoryGirl 写入未知属性ad_id

.erb 、 .rhtml 和 .html.erb 有什么区别?