Rails 3 adding fields to a table
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
精彩评论