I’m sorry, I made a mistake. I was working client-server, and when changing code, sometimes the server needs to be restarted to make the changes active (I assume that the code was server sided). After restarting it worked fine. The situation is now:
index(pid) in table1(id)
The index of table2 refers to the id of table1. This works fine, but only after adding key(id) on table1. I also do not understand why that works, but it does.