1

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_password
  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?

4

2 に答える 2

2

あなたの構文はダウンマイグレーションに対して正しいです。なぜそれが機能しないのかわかりません。移行に変更を加えて、次のことを行うことができます。

rake db:reset

他のすべてが失敗した場合に、新しい移行をキャプチャします。

于 2011-07-12T17:42:13.403 に答える
1

手動で列を削除しsqlitebrowserて削除しました。encrypted_passwordこれで問題は解決しました。その後も上下に移動してみましたが、すべてうまくいきます。ありがとうクリス。

于 2011-07-29T06:56:41.983 に答える