Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Problem with adding id in migration

#1906

I use Rails 2.2.2 with sqlite3 3.5.6 under Vista.

Firstly I created a table without id, but later I found it wasn't good idea and I wanted to add id column with migration:

class AddIdToPersonRelation < ActiveRecord::Migration def self.up

add_column :person_relations, :id, :integer

end

def self.down

remove_column :person_relations, :id

end end

Then I run migration: rake db:migrate And I found that Rails didn't set id field as primary key, so when I added something to the table, id was set to nil. It wasn't what I expected.

Then I run: rake db:schema:load And it created all tables again and person_relations table had correct primary key.

I think that both methods (db:migrate and db:schema:load) should give the same results.

Maybe I am wrong (I am new in ruby and rails).

Reported by klew · February 7th, 2009 @ 04:50 PM

State: invalid
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Pratik
    Pratik
    • Assigned user set to Pratik
    • State changed from new to invalid

    You should use :primary_key.

    Thanks.

    March 8th, 2009 @ 01:12 PM

  2. bingbing