I created a model using:
rails generate model SavingsItem
I then ran rake db:migrate.
Now, I want to rename the model to SavingsProduct
I did a rake db:rollback and then went directly into my migration file and change the model name and table name. However, when I run rake db:migrate again, it creates the right table name in my database, but creates savings_item.rb still.
Why does this happen?
Here is my migration file:
class CreateSavingsProducts < ActiveRecord::Migration
def change
create_table :savings_products do |t|
t.string :name, :limit => 50
t.string :description, :limit => 200
t.decimal :price, :precision => 10, :scale => 2
t.string :buy_url, :limit => 200
t.string :image_url, :limit => 200
t.integer :image_width, :limit => 11
t.integer :image_height, :limit => 11
t.timestamps
end
end
end
Migrations only alter the database; they don’t create or alter any files (except schema.rb). Generators are what create and alter files, including migration files.
If you already have the model generated, you can simply change its name manually. Change
class SavingsItemtoclass SavingsProductand rename the file fromsavings_item.rbtosavings_product.rb.