Tag Archives: Assets

DB: the solution of table already exist when migrating

        When running rake DB: migrate, you sometimes find an error in rake abort. Rake says that a table already exists, so it can’t do the work of this migrate. This table does exist, so how can rake skip this table or force it to be overridden?There is one area that needs to be modified:

Original migrate file:

Ruby code

 

    class   CreateProducts  & lt;   ActiveRecord::Migration      def   self.up        create_ table  : products   do  | t|          t.column  : title,  : string          t.column  : description,  : text          t.column  : image_ url,  : string        end      end        def   self.down        drop_ table  : products      end    end   

    Modified migrate file:

    Ruby code

     

      class   CreateProducts  & lt;   ActiveRecord::Migration      def   self.up        create_ table  : products,  : force  =& gt;   true   do  | t|          t.column  : title,  : string          t.column  : description,  : text          t.column  : image_ url,  : string        end      end        def   self.down        drop_ table  : products      end    end   

      Do you see that in create_ In the parameter of table, add: force = & gt; True.