Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
Add columns using migration.
4 Posts
Add columns using migration.

I am new to migration. While reffering to a book i got to know that, if i want to add a column "price" to a table "products", i need to create a migration like this, ruby script/migration add_column_to_products price:decimal.

Suppose i have created and applied the above migration and later i need to add another column "description", i think i do have to repeat the same procedure as i did above. That is, generate another migration using command ruby script/migration add_column_to_products description:string. By doing this i am getting an error like

"Another migration is already named add_column_to_products: db/migrate/20090214065128_add_column_to_products.rb"

Please help me to clear the following doubts, 1. Am i doing in the wrong way? 2. Anyway the filename will be appended with the dates and time, so that would be unique, what is behind the error message?

Any help is highly appreciated. Thanks in advance, nithy"

ruby script/migration add_column_to_products description:string

The name you pick needs to be unique. If you open up those two migration files they have the same class name which is why you are getting the error. Be more specific on your name and you will be OK.

add_description_to_products add_price_to_products

The developer should use a descriptive name for the migration (=unique). At least you get an empty migration. If you follow conventions you get an almost complete migration (without default or null settings).

The mentioned number is used to check whether the migration has been applied to the database (check table schema_information). In addition the number manages the order of the migrations.

Thanks Brian and Ronald. I am clear with my doubts and it is working fine. nithy"

4 Posts
Login to add your message