{"action":"created","issue":{"url":"https://api.github.com/repos/thoughtbot/shoulda-matchers/issues/682","labels_url":"https://api.github.com/repos/thoughtbot/shoulda-matchers/issues/682/labels{/name}","comments_url":"https://api.github.com/repos/thoughtbot/shoulda-matchers/issues/682/comments","events_url":"https://api.github.com/repos/thoughtbot/shoulda-matchers/issues/682/events","html_url":"https://github.com/thoughtbot/shoulda-matchers/issues/682","id":60546138,"number":682,"title":"validate_uniqueness_of and foreign key problem","user":{"login":"ElamT","id":2923255,"avatar_url":"https://avatars.githubusercontent.com/u/2923255?v=3","gravatar_id":"","url":"https://api.github.com/users/ElamT","html_url":"https://github.com/ElamT","followers_url":"https://api.github.com/users/ElamT/followers","following_url":"https://api.github.com/users/ElamT/following{/other_user}","gists_url":"https://api.github.com/users/ElamT/gists{/gist_id}","starred_url":"https://api.github.com/users/ElamT/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ElamT/subscriptions","organizations_url":"https://api.github.com/users/ElamT/orgs","repos_url":"https://api.github.com/users/ElamT/repos","events_url":"https://api.github.com/users/ElamT/events{/privacy}","received_events_url":"https://api.github.com/users/ElamT/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/thoughtbot/shoulda-matchers/labels/Bug","name":"Bug","color":"e10c02"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-03-10T18:27:38Z","updated_at":"2015-10-28T07:48:33Z","closed_at":null,"body":"Hi! \r\nI have one model with two column (applicant_id and career_id) and both are foreign keys. When I a try to validate applicant_id or career_id is uniqueness\r\n\r\n should validate_uniqueness_of(:applicant_id)\r\nor\r\n should validate_uniqueness_of(:career_id) \r\n\r\nI got follow exception \r\n\r\nFailure/Error: should validate_uniqueness_of(:applicant_id)\r\n     ActiveRecord::InvalidForeignKey:\r\n       PG::ForeignKeyViolation: ERROR:  insert or update on table \"degrees\" violates foreign key constraint \"fk_rails_25163bce0a\"\r\n       DETAIL:  Key (applicant_id)=(0) is not present in table \"applicants\".\r\n       : INSERT INTO \"degrees\" (\"applicant_id\", \"created_at\", \"updated_at\") VALUES ($1, $2, $3) RETURNING \"id\"\r\n\r\nBut if I delete the foreing key constraint this problem does not occur"},"comment":{"url":"https://api.github.com/repos/thoughtbot/shoulda-matchers/issues/comments/151754775","html_url":"https://github.com/thoughtbot/shoulda-matchers/issues/682#issuecomment-151754775","issue_url":"https://api.github.com/repos/thoughtbot/shoulda-matchers/issues/682","id":151754775,"user":{"login":"itsmechlark","id":5423610,"avatar_url":"https://avatars.githubusercontent.com/u/5423610?v=3","gravatar_id":"","url":"https://api.github.com/users/itsmechlark","html_url":"https://github.com/itsmechlark","followers_url":"https://api.github.com/users/itsmechlark/followers","following_url":"https://api.github.com/users/itsmechlark/following{/other_user}","gists_url":"https://api.github.com/users/itsmechlark/gists{/gist_id}","starred_url":"https://api.github.com/users/itsmechlark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/itsmechlark/subscriptions","organizations_url":"https://api.github.com/users/itsmechlark/orgs","repos_url":"https://api.github.com/users/itsmechlark/repos","events_url":"https://api.github.com/users/itsmechlark/events{/privacy}","received_events_url":"https://api.github.com/users/itsmechlark/received_events","type":"User","site_admin":false},"created_at":"2015-10-28T07:48:33Z","updated_at":"2015-10-28T07:48:33Z","body":"I tried:\r\n\r\n``"}}