Prefixing primary key with table alias to avoid SQL errors

Fixes #5044