开发者

Rails 3 adding fields to a table

开发者 https://www.devze.com 2023-01-30 17:19 出处:网络
ok i am a noob and i want to know how to add fields to a migration in rails 3, additionally i am using Typus and would like to know if i need to add 开发者_如何学运维these fields manually or can i jus

ok i am a noob and i want to know how to add fields to a migration in rails 3, additionally i am using Typus and would like to know if i need to add 开发者_如何学运维these fields manually or can i just regenerate the typus and it will just pick the new fields up?

Thanks in advance

Robbie


Migrations are used to add fields to the database, not tell Rails about fields.

Rails will actually inspect the table for its fields, so if you have an existing table, you can create a model called spy.rb and it will know about all fields in spies

To use migrations, run rails generate migration AddScreenshotColumns. Then that file can become:

class AddScreenshotColumnsToTemplate < ActiveRecord::Migration
  def self.up
    add_column :templates, :screenshot_file_name,    :string
  end

  def self.down
    remove_column :templates, :screenshot_file_name
  end
end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号