Ruby on rails: rake migrate down doesn't seem to be working
I generated a migration that adds a column called encrypted_password to the users table present in my databse. This was generated automatically by rails using the command:
rails generate migration add_password_to_users encrypted_password:string
class AddPasswordToUsers < ActiveRecord::Migration
def self.up
add_column :users, :encrypted_password, :string
end
def self.down
remove_column :users, :encrypted_passwo开发者_如何转开发rd
end
end
I'm trying to remove and remake the encrypted_password column in the users_table, so this is what I'm doing:
rake db:migrate:down VERSION=20110712172013
(thats the timestamp of the migration)
rake db:migrate
(Ive also tried rake db:migrate:redo VERSION=20110712172013
)
I get this error: SQLite3::SQLException: duplicate column name: encrypted_password: ALTER TABLE "users" ADD "encrypted_password" varchar(255)
So for some reason, the down migration isn't really removing the column. Anyone have an idea why?
Your syntax is correct for the down migration. Don't know why it wouldn't be working. You could make your changes in your migration and do:
rake db:reset
To capture your new migration if all else fails.
I just whipped out sqlitebrowser
and deleted the encrypted_password
column manually. That fixed the problem. I tried migrating up and down after that too, it all works fine. Thanks Chris.
精彩评论