Reputation: 9682
I have been learning rails, and am having an issue making a migration by hand. What I have done:
The filename is:
20150825194806_slug_unique_vacations.rb
which I made up. I tried cutting and pasting a migration and I named the class based on what I thought made sense:
class SlugUniqueIndex < ActiveRecord::Migration
def change
add_index :vacations, [:slug], :unique => true
end
end
but I get this error:
cchilders@cody_pc:~/projects/rails_projects/vacation$ rake db:migrate
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
uninitialized constant SlugUniqueVacations
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
What is the correct way to migrate where you only want to make a single field that already exists in a table unique?
Upvotes: 0
Views: 44
Reputation: 376
Migration file name and class name must be same.
class SlugUniqueVacations < ActiveRecord::Migration
def change
add_index :vacations, [:slug], :unique => true
end
end
Upvotes: 4