I have a table with data and I would like to add friendly_id.
I don't know how to build my migration as I can't create a table with :null=>false when there's data in it. What I would like to do, was for the migration to run the FriendlyId so it builds the slug and inserts it to the database.
My current Migration is as follows:
class AddSlugToSite < ActiveRecord::Migration
def up
add_column :site, :slug, :string
change_column_null :site, :slug, false
add_index :site, :slug, :unique => true
end
def down
remove_column :site, :slug, :string
end
end
And my model:
class Site < ActiveRecord::Base
extend FriendlyId
friendly_id :name, :use => :slugged
end
This doesn't work as Rails can't create a field with null=>false when there's already data in there.
How can I do it?
Thanks