Weblog - 1 items for migrations
Ruby on Rails Making string primary key work for tests
If you want to have primary keys with a type of :string in Ruby on Rails you can do so by using the change_column method after creating a table in the migration.
eg.
create_table "g_languages", :force => true do |t|
t.column "name", :string, :limit => 50, :default => "", :null => false
end
change_column "g_languages", :id, :string, {:limit => 5, :default => "", :null => false}
Problem is if you want to use this Model in your tests the id is autmatically set to :integer and youre string change does not come accross. (The schema.rb is created without any id/primary key info so :integer is assumed)
The fix
Alter the table using ActiveRecord::Migration in test_helper.rb before the fixtures are loaded.
eg.
migrater = ActiveRecord::Migration
migrater.change_column :g_languages, :id, :string, {:limit => 5, :default => "", :null => false}
fixtures :all
