Search code examples
ruby-on-railsactiverecordrakemigrate

Ruby on Rails - Creating Wrong Schema.rb File?


Am I correct in saying that the db/schema.rb file should be pulling from the db/migrate files on rake db:migrate? I am running a rake db:migrate and it is adding a table that isn't defined in the migrate, nor the models. Any ideas?

Migrate Files (just one):

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :email
      t.string :hashed_password
      t.timestamps
    end
  end
end

Resulting Schema after rake:

ActiveRecord::Schema.define(:version => 20121113214159) do

  create_table "user_categories", :force => true do |t|
    t.string   "title"
    t.string   "description"

    t.datetime "created_at",  :null => false
    t.datetime "updated_at",  :null => false
  end

  create_table "users", :force => true do |t|
    t.string   "email"
    t.string   "hashed_password"

    t.datetime "created_at",                  :null => false
    t.datetime "updated_at",                  :null => false
  end

end

I had added a user_categories scaffolding earlier, but incorrectly so I destroyed it. Not sure where I went wrong in destroying parts...


Solution

  • If you don't have any important data on your db, you could run rake db:drop then rake db:create. Then run rake db:migrate and it should update your schema clean.