This is a discussion on How to Migrate DB within the Ruby forums, part of the Web Development category; I am new to Ruby on Rails I have Problem while migrating Db Can someone Plz explain...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| There are lot in migration. I have given the sample for db migration. ActiveRecordMigration allows you to use Ruby to define changes to your database schema, making it possible to use a version control system to keep things synchronised with the actual code. This has many uses, including:
Create the migration Run the generator: ruby script/generate migration add_a_new_table This will create the file db/migrate/001_add_a_new_table.rb Edit the code to tell it what to do. The method self.up is used when migrating to a new version, self.down is used to roll back any changes if needed. The class name needs to be the same as the migration name (i.e. db/migrate/001_add_a_new_table needs a class name of AddANewTable). The ID column will be created automatically, so don’t do it here as well. class AddANewTable < ActiveRecord::Migration def self.up create_table :users do |table| table.column :name, :string table.column :login, :string, :null => false # This column will contain an MD5 hash. table.column : password, :string, :limit => 32, :null => false table.column :email, :string end end def self.down drop_table :users end end Valid column types are integer, float, datetime, date, timestamp, time, text, string, binary, and boolean. You can also populate or modify data in a migration. A common usage would be to populate the values in a lookup table: def self.up create_table :statuses do |t| t.column :name, :string end Status.create :name=>"Complete" Status.create :name=>"Incomplete" end Run the migration rake db:migrate Hope the above steps will help you to solve the problem. Or give me the detailed explanation about your problem which you have faced in migration. thanks ![]()
__________________ Karpagarajan. R Necessity is the mother of invention |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Migrate MS Access data to Oracle | it.wily | Database Support | 4 | 09-14-2007 05:21 AM |