RAILS: FORCE MIGRATION

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.

class CreateCandy < ActiveRecord::Migration
  def self.up
    create_table :candies, :force => true do |t|
      t.string :name
      t.string :type
 
      t.timestamps
    end
  end
 
  def self.down
    drop_table :candies
  end
end

你可能感兴趣的:(Ruby,UP,Rails,ActiveRecord)