Apply upstream PR #77 to fix use of primary_key