PrimaryKeyColumn
This class is used to create a unique index in every table you create. In the context of a table that inherits from the Model class, exactly one PrimaryKeyColumn is required.
Below is an example of creating an id column as a primary key in a table named Post.
class Post(Model):
__tablename__: Optional[TableColumn] = TableColumn(name="users")
id = PrimaryKeyColumn(type="int", auto_increment=True)
#...rest of your columns
The following are the arguments that the PrimaryKeyColumn class accepts.
Argument |
Description |
Type |
Default |
|---|---|---|---|
|
The datatype of your primary key. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Note
Each table you create that inherits from the Model class requires this column to be available unless the table is a joint-table.