piccolo icon indicating copy to clipboard operation
piccolo copied to clipboard

Foreign Keys that reference non pk columns

Open dantownsend opened this issue 3 years ago • 2 comments

Discussed in https://github.com/piccolo-orm/piccolo/discussions/393

Originally posted by theelderbeever January 13, 2022 Is it possible to create a foreign key on a table that references a column other than the primary key on a table? The documentation seems to imply that you can only pass a table to ForeignKey and it picks up the pk. I would like to do something like the following...

class Contract(BaseTable):

    address = Varchar(index=True, required=True, null=False, unique=True)

class Log(BaseTable):

    contract_address = ForeignKey(Contract.address)

Is there a way to accomplish this?

dantownsend avatar Jan 13 '22 09:01 dantownsend

Reopening, as there are still changes required to Piccolo Admin and Piccolo API.

dantownsend avatar Jan 16 '22 21:01 dantownsend

@dantownsend Fix for Piccolo Api and Piccolo Admin is here

sinisaos avatar Feb 09 '22 10:02 sinisaos