Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

change_column fails to fully respect provided fk and index names #149

Open
wrkrb33 opened this issue Mar 17, 2014 · 0 comments
Open

change_column fails to fully respect provided fk and index names #149

wrkrb33 opened this issue Mar 17, 2014 · 0 comments
Labels

Comments

@wrkrb33
Copy link

wrkrb33 commented Mar 17, 2014

I am iteratively developing a script to add foreign key constraints throughout a postgres database. In some cases the usual concatenation of table and column names to construct constraint and index names produces names that exceed the permitted length, so in those cases I am providing my own names. E.g.,

change_column("staffing_plan_category_item_pairings", "staffing_plan_category_id", :integer, {:foreign_key=>{:name=>"fk_spcip_sp_category_id"}, :index=>{:name=>"fk__spcip_sp_category_id"}})

This works fine the first time through. However, if I re-run the migration, schema_plus wants to first make an attempt to drop the constraint if, but it does that without reference to the name I've provided, resulting in an error:

NOTICE:  identifier "fk_staffing_plan_category_item_pairings_staffing_plan_category_id" will be truncated to "fk_staffing_plan_category_item_pairings_staffing_plan_category_"
rake aborted!
PG::UndefinedObject: ERROR:  constraint "fk_staffing_plan_category_item_pairings_staffing_plan_category_" of relation "staffing_plan_category_item_pairings" does not exist
: ALTER TABLE "staffing_plan_category_item_pairings" DROP CONSTRAINT fk_staffing_plan_category_item_pairings_staffing_plan_category_id

I am able to work around the problem by manually deleting the constraints and indexes in question.

@ronen ronen added the bug label Aug 19, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants