Make sure table exists when checking primary key

When asking for a table's primary key column, returning 0 doesn't make
sense if the table doesn't exist in the database. We throw an exception
instead.