#O2M can't choose foreign key

9 messages · Page 1 of 1 (latest)

spark sorrel
#

Hi everyone,
I have a small problem when I want to make an O2M relationship. When I configure the relationship, I can't choose the foreign key...
If I type "id" anyway, I get the following error:

[INVALID_PAYLOAD] Field "id" in collection "socials" is a primary key

Does anyone know where this might be coming from?

west needle
spark sorrel
#

@west needle Thank you very much for your answer! But when I type the foreign key manually I've [INVALID_PAYLOAD] Field "id" in collection "socials" is a primary key error...

west needle
#

You can't link from a o2m to the primarykey, the field chosen here will save the id of the collection to that field and you cannot update primarykeys

spark sorrel
#

So I need to create an M2O relationship in my collection 1 and normally the O2M relationship, once connected to the M2O relationship should work?

west needle
#

You don't have to add the m2o (on the directus end) but effectively yeah m2o and o2m are the reverse of eachother so one will come with the other in a properly configured relation 🙂

#

if you prefer not to add the m2o directly you can just type any name of the foreign key you want to use and that will be created for you

spark sorrel
#

Ok, and in the 2nd case, to create it automatically, if I put a foreign key that doesn't exist yet (so not in blue in the interface), it should be ok?

west needle
#

that should be created when you save