piccolo
piccolo copied to clipboard
Foreign Keys that reference non pk columns
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?
Reopening, as there are still changes required to Piccolo Admin and Piccolo API.
@dantownsend Fix for Piccolo Api and Piccolo Admin is here