Column Class
In the context of a database table, each property marked as a column in a model is treated as an individual attribute.
Here’s an example of how to define a column in a table using the Column class
username = Column(type="text", nullable=False, default="Hello there!!")
Here are some other options that you can pass to the Column
Argument |
Description |
Type |
Default |
|
Required datatype of a column. |
|
– |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Note
Talking about data types, each dialect has its own accepted values. Here is a list of types supported by each and every dialect:
Column Data types
In this section we will list all the datatypes that are supported for each dialect.
mysql
Data Type |
Description |
|---|---|
|
Integer data type. |
|
Small integer data type. |
|
Big integer data type. |
|
Floating-point number data type. |
|
Double-precision floating-point number data type. |
|
Numeric or decimal data type. |
|
Text data type. |
|
Variable-length character data type. |
|
Fixed-length character data type. |
|
Boolean data type. |
|
Date data type. |
|
Time data type. |
|
Timestamp data type. |
|
JSON (JavaScript Object Notation) data type. |
postgres
Data Type |
Description |
|---|---|
|
Integer data type (Alias: |
|
Small integer data type (Alias: |
|
Big integer data type (Alias: |
|
Auto-incrementing integer data type (Alias: |
|
Auto-incrementing big integer data type (Alias: |
|
Auto-incrementing small integer data type (Alias: |
|
Real number data type (Alias: |
|
Double-precision floating-point number data type (Alias: |
|
Numeric data type (Alias: |
|
Text data type. |
|
Variable-length character data type. |
|
Fixed-length character data type. |
|
Boolean data type. |
|
Date data type. |
|
Time data type. |
|
Timestamp data type. |
|
Time interval data type. |
|
UUID (Universally Unique Identifier) data type. |
|
JSON (JavaScript Object Notation) data type. |
|
Binary JSON (JavaScript Object Notation) data type. |
|
Binary data type (Array of bytes). |
|
Array data type. |
|
IP network address data type. |
|
Classless Inter-Domain Routing (CIDR) address data type. |
|
MAC (Media Access Control) address data type. |
|
Text search vector data type. |
|
Geometric point data type. |
|
Geometric line data type. |
|
Geometric line segment data type. |
|
Geometric box data type. |
|
Geometric path data type. |
|
Geometric polygon data type. |
|
Geometric circle data type. |
|
Key-value pair store data type. |
sqlite
Data Type |
Description |
|---|---|
|
Integer data type. |
|
Small integer data type. |
|
Big integer data type. |
|
Real number data type. |
|
Double-precision floating-point number data type. |
|
Numeric data type. |
|
Text data type. |
|
Variable-length character data type. |
|
Fixed-length character data type. |
|
Boolean data type. |
|
Date data type. |
|
Time data type. |
|
Timestamp data type. |
|
JSON (JavaScript Object Notation) data type. |
Note
Every table that is not a joint_table is required to have a primary key column and this column should be 1. Let’s talk about the PrimaryKeyColumn