PyCharm
 
Get PyCharm
You are viewing the documentation for an earlier version of PyCharm.

Foreign keys

Last modified: 22 September 2023

Foreign key relationships specify how tables relate to each other and indicate relationships between tables. PyCharm recognizes foreign key relationships in your database schema and uses them to construct JOIN clauses. You can see these relationships in the auto-completion list, data navigation, and diagrams.

In PyCharm, you can use explicit foreign keys or create virtual foreign keys.

Foreign keys can be seen in the Database tool window. You can see a reference on node and object icons in the Data sources and their elements chapter of Database tool window topic.

For the table column icons, refer to Possible icon combinations for columns.

A foreign key is a field or a collection of fields in one table that refers to the primary key in another table. When you create or modify a table, you can clearly define those keys:

The table that contains a foreign key is a child table. The table that contains a candidate key is a referenced or target table. If your database contains explicit foreign key relationships, PyCharm automatically uses them in auto-completion, data navigation, and diagrams.

In the following example, activity.activity_id is a primary key, while visitor.activity_id is a foreign key.

Explicit foreign keys