Skip to content

Foreign Keys that reference non pk columns #394

Description

@dantownsend

Discussed in #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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions