[Rails] foreign keys on migration

Craig White
2006-03-25T16:37:13Z

I have reached a development plateau and now want to integrate some of
the rails niceties that I passed over to get the system online.

I am fooling with migrations. I am using postgresql. I put in my
migration script (at the end of the ''up'' method, the following
raw sql
code...

    # set up primary key restratints for PostgreSQL
    execute ''ALTER TABLE ONLY referral_notes ADD CONSTRAINT
referral_notes_pkey PRIMARY KEY (id)''
    execute ''ALTER TABLE ONLY placements ADD CONSTRAINT placements_pkey
PRIMARY KEY (id)''
    execute ''ALTER TABLE ONLY case_managers ADD CONSTRAINT
case_managers_pkey PRIMARY KEY (id)''
    execute ''ALTER TABLE ONLY facilities ADD CONSTRAINT facilities_pkey
PRIMARY KEY (id)''
    execute ''ALTER TABLE ONLY clients ADD CONSTRAINT clients_pkey
PRIMARY KEY (id)''
    execute ''ALTER TABLE ONLY users ADD CONSTRAINT users_pkey PRIMARY
KEY (id)''

    # set up foreign key restratints for PostgreSQL
    execute ''ALTER TABLE ONLY clients ADD CONSTRAINT fk_cp_case_manager
FOREIGN KEY (case_manager_id) REFERENCES case_managers(id)''
    execute ''ALTER TABLE ONLY placements ADD CONSTRAINT fk_cp_client
FOREIGN KEY (client_id) REFERENCES clients(id)''
    execute ''ALTER TABLE ONLY placements ADD CONSTRAINT fk_cp_facility
FOREIGN KEY (facility_id) REFERENCES facilities(id)''
    execute ''ALTER TABLE ONLY placements ADD CONSTRAINT
fk_cp_case_manager FOREIGN KEY (case_manager_id) REFERENCES
case_managers(id)''
    execute ''ALTER TABLE ONLY referral_notes ADD CONSTRAINT
fk_cp_placement FOREIGN KEY (placement_id) REFERENCES placements(id)''

The primary key constraints are indeed all created but the foreign keys
constraints are not created.

Anyone care to toss me a bone here?

Craig