Hi
When a migration is created, rails add a column named id, which is defined as an integer, as table’s primary key column. Sometimes can happen that you don’t want to name your primary key column id using rails. The way you have to write your migration is this one (rails use integer type by default):
def self.up
create_table :airport, :primary_key => :airport_id do |t|
t.string :iso_code, :limit =>3, :null => false
t.string :name, :limit =>150, :null => false
t.integer :city_id, :null => false
end
end
If you have a “many to many” table probably you don’t want to have this id column in your table and you want to define two columns as primary key. This is the way you have to write a migration if you want to define this primary key:
def self.up
create_table :airports_cities, :primary_key => [:airport_id, city_id] do |t|
t.integer :distance, :null => false
end
end
In both examples, columns defined as primary key don’t have to be defined because rails do it for you. Using this, you won’t have an id column in your table and you’ll be able to use whatever you want as primary key (even strings).
Hope this helps (to my fish-like memory or to somebody else’s brain).
M.