Posted By

chrisaiv on 10/27/08


rails ruby migrations

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Rails: Force Migration

 / Published in: Ruby

Suppose you already have a database with a table named candy and now you want to start using migrations. If you try to run a migration with a pre-existing table, Rails will error. So by placing :force => true, you are forcefully wiping the table. After you've performed your migration, you normally want to return the Boolean to false.

  1. class CreateCandy < ActiveRecord::Migration
  2. def self.up
  3. create_table :candies, :force => true do |t|
  4. t.string :name
  5. t.string :type
  7. t.timestamps
  8. end
  9. end
  11. def self.down
  12. drop_table :candies
  13. end
  14. end

Report this snippet  

You need to login to post a comment.