user3114054
user3114054

Reputation:

No such column: admin_users.password

When I run my migrations in rails, I get back a sql error saying that no such column:admin_users.password exists. When I SHOW FIELDS it's clearly there. I'm sure this is because I missed something somewhere. In this case, understanding what went wrong is much more important to me than fixing the issue since I keep getting stuck with my database in a broken state.

First Migration:

    class CreateUsers < ActiveRecord::Migration

      def up
        create_table :users do |t|
          t.column "first_name", :string, :limit => 25
          t.string "last_name", :limit => 50
          t.string "email", :default => "", :null => false
          t.string "password:", :limit => 40
          # t.datetime "created_at"
          # t.datetime "updated_at"
          # The above two are created automatically by the below command
          t.timestamps
        end
      end

      def down
         drop_table :users
      end

end

Second Migration:

class AlterUsers < ActiveRecord::Migration


  def up
rename_table("users", "admin_users")
add_column("admin_users", "username", :string, :limit => 25, :after => "email")
change_column("admin_users", "email", :string, :limit => 100)
rename_column("admin_users", "password", "hashed_password")
puts "*** Adding an index is next***"
add_index("admin_users", "username")
  end

  def down
remove_index("admin_users", "username")
rename_column("admin_users", "hashed_password", "password")
change_column("admin_users", "email", :default => "", :null => false)
remove_column("admin_users", "username")
rename_table("admin_users", "users")
    end
end


=>==  CreateUsers: migrated (0.0163s) ===========================================

==  AlterUsers: migrating =====================================================
-- rename_table("users", "admin_users")
-> 0.0034s
-- add_column("admin_users", "username", :string, {:limit=>25, :after=>"email"})
-> 0.0158s
-- change_column("admin_users", "email", :string, {:limit=>100})
-> 0.2273s
-- rename_column("admin_users", "password", "hashed_password")
rake aborted!
An error has occurred, all later migrations canceled:

No such column: admin_users.password

Upvotes: 0

Views: 740

Answers (1)

Leonid Shevtsov
Leonid Shevtsov

Reputation: 14189

That's because you called your column password: with a colon in the first migration.

I bet that's because of a typo in the rails generate model commandline. It's horribly un-foolproof.

Upvotes: 3

Related Questions