Error "there is no unique constraint matching given keys" migrating DB to latest canvas release

126 views
Skip to first unread message

peter.h...@gmail.com

unread,
May 31, 2013, 4:19:00 AM5/31/13
to canvas-l...@googlegroups.com
I'm trying to upgrade to the latest version of canvas. When I try to run 

RAILS_ENV=production bundle exec rake db:migrate

I get the error:

PG::Error: ERROR:  there is no unique constraint matching given keys for referenced table "quizzes"
: ALTER TABLE "quiz_statistics" ADD CONSTRAINT "quiz_statistics_quiz_id_fk" FOREIGN KEY ("quiz_id") REFERENCES "quizzes"(id)

Anyone got an idea, how to solve this?

Thanks,

Peter

Cody Cutrer

unread,
May 31, 2013, 10:47:40 AM5/31/13
to canvas-l...@googlegroups.com
Can you post the output of psql with the following command:

\d quizzes

Thanks,

Cody Cutrer
Software Engineer
Instructure


--
 
---
You received this message because you are subscribed to the Google Groups "Canvas LMS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to canvas-lms-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

peter.h...@gmail.com

unread,
Jun 1, 2013, 4:27:19 AM6/1/13
to canvas-l...@googlegroups.com
Thanks for your reply.

In the meantime I solved the problem.

1) I removed 

add_foreign_key :quiz_statistics, :quizzes

from

20130508214241_add_quiz_statistics_foreign_key.rb

and did the migration.

2) After that I added the line again and did the update again. It worked fine now. 

Nevertheless if I do

/d I get the output

Did not find any relation named "quizzes".

Is this correct?

Cody Cutrer

unread,
Jun 3, 2013, 2:59:23 PM6/3/13
to canvas-l...@googlegroups.com
Peter,

Commenting out that line means that it was never added, and when you re-ran it wasn't added either, cause the migration had already been run. I'm not sure why your \d didn't find the quizzes table (likely because you were using a different user and it wasn't using the correct schema search_path). Anyways, you're probably okay. The foreign key is just extra protection around bad data getting into the database, but the app should never try to put bad data in in the first place. We monitor database errors here at Instructure, and haven't seen anything try to violate that constraint in our environment, so I wouldn't worry about it if I was you.

Cody Cutrer
Software Engineer
Instructure
Reply all
Reply to author
Forward
0 new messages