From: Rick DeNatale Date: 2007-11-11T02:45:06+09:00 Subject: Re: why this rake db:migrate error On Nov 10, 2007 12:30 PM, darius wrote: > hello > > I'm getting a rake db:migrate error which I can't understand (newbie). > > -- add_column(:stories, :votes_count, :integer, {:default=>0}) > rake aborted! > Mysql::Error: #42S21Duplicate column name 'votes_count': ALTER TABLE > stories ADD > `votes_count` int(11) DEFAULT 0 > > (See full trace by running task with --trace) > > the error is in > > 005_add_counter_cache_to_stories.rb > > class AddCounterCacheToStories < ActiveRecord::Migration > add_column :stories, :votes_count, :integer, :default => 0 > def self.up > Story.find(:all).each do |s| ... Why is the add_column outside of the up method? This means that it will be executed at the time the AddCounterCacheToStores class is created, which I think will happen whatever the current schema version is, at least that would explain what you are seeing. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/