Rails uses this timestamp to determine which migration For exampleĢ0080906120000_create_products.rb should define class CreateProducts andĢ0080906120001_add_details_to_products.rb should defineĪddDetailsToProducts. Should match the latter part of the file name. The name of the migration class (CamelCased version) Identifying the migration followed by an underscore followed by the name YYYYMMDDHHMMSS_create_products.rb, that is to say a UTC timestamp Migrations are stored as files in the db/migrate directory, one for each change :price, :integer end end end Copy 2 Creating a Migration 2.1 Creating a Standalone Migration change :price, :string end end def down change_table :products do | t | t. You will have to rollback the changes that were made by hand.Ĭlass ChangeProductsPrice < ActiveRecord :: Migration def up change_table :products do | t | t. Then when a migration fails the parts of it that succeeded will not be rolledīack. On databases that support transactions with statements that change the schema, This migration back, it will remove the table. #Dbschema one to one relationship how to#Active Record knows how to reverse this migration as well: if we roll Note that we define the change that we want to happen moving forward in time.īefore this migration is run, there will be no table. These special columns are automatically managed by Active Record The timestamps macro adds two columns, created_at and Will also be added implicitly, as it's the default primary key for all Active Name and a text column called description. This migration adds a table called products with a string column called Class CreateProducts < ActiveRecord :: Migration def change create_table :products do | t | t.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |