Skip to main content

Fields

Fields define the columns of your database tables. Ryx provides 30+ field types with built-in validation and type conversion.

Common Field Options

Every field accepts these common options:

OptionTypeDescription
nullboolAllow NULL in the database (default: False)
blankboolAllow empty value in validation (default: False)
defaultAny | callableDefault value or callable
uniqueboolUNIQUE constraint
db_indexboolCreate an index on this column
choiceslistRestrict values to this list
validatorslistAdditional validators
editableboolInclude in save() (default: True)
help_textstrDocumentation string
verbose_namestrHuman-readable label
db_columnstrOverride column name
primary_keyboolMake this the primary key
CharField(
max_length=200,
null=True,
blank=True,
default="",
unique=False,
db_index=False,
choices=["draft", "published"],
validators=[MaxLengthValidator(200)],
db_column="post_title",
)

Integer Fields

FieldSQL TypePython TypeExtra Options
AutoFieldSERIALintAuto-increment PK
BigAutoFieldBIGSERIALint64-bit auto-increment
SmallAutoFieldSMALLSERIALint16-bit auto-increment
IntFieldINTEGERintmin_value, max_value
SmallIntFieldSMALLINTintmin_value, max_value
BigIntFieldBIGINTintmin_value, max_value
PositiveIntFieldINTEGERintImplicit min_value=0
class Product(Model):
stock = IntField(default=0, min_value=0)
price_cents = PositiveIntField()
rating = SmallIntField(min_value=1, max_value=5)

Text Fields

FieldSQL TypePython TypeExtra Options
CharFieldVARCHAR(n)strmax_length, min_length, strip
TextFieldTEXTstrmin_length
SlugFieldVARCHAR(50)strAuto slug validation
EmailFieldVARCHAR(254)strAuto email validation
URLFieldVARCHAR(200)strAuto URL validation
IPAddressFieldVARCHAR(15)strAuto IPv4 validation
class User(Model):
name = CharField(max_length=100, min_length=2)
email = EmailField(unique=True)
website = URLField(null=True, blank=True)
bio = TextField(null=True, blank=True)
slug = SlugField(unique=True)

Date & Time Fields

FieldSQL TypePython TypeExtra Options
DateFieldDATEdateauto_now, auto_now_add
DateTimeFieldTIMESTAMPdatetimeauto_now, auto_now_add
TimeFieldTIMEtime
DurationFieldBIGINTtimedeltaStored as microseconds
class Event(Model):
date = DateField()
starts_at = DateTimeField()
ends_at = DateTimeField(null=True)
duration = DurationField(null=True)
created_at = DateTimeField(auto_now_add=True)
updated_at = DateTimeField(auto_now=True)

Special Fields

FieldSQL TypePython TypeExtra Options
BooleanFieldBOOLEANbool
NullBooleanFieldBOOLEANbool | NoneImplicit null=True
FloatFieldDOUBLE PRECISIONfloatmin_value, max_value
DecimalFieldNUMERIC(p,s)Decimalmax_digits, decimal_places
UUIDFieldUUIDUUIDauto_create
JSONFieldJSONBdict | list
BinaryFieldBYTEAbytes
ArrayFieldT[]listbase_field
from decimal import Decimal
import uuid

class Config(Model):
active = BooleanField(default=True)
score = FloatField(null=True)
price = DecimalField(max_digits=10, decimal_places=2)
ref_id = UUIDField(auto_create=True)
metadata = JSONField(null=True)
tags = ArrayField(base_field=CharField(max_length=50), null=True)
data = BinaryField(null=True)

Relationship Fields

FieldSQL TypeDescription
ForeignKeyINTEGERMany-to-one relationship
OneToOneFieldINTEGER UNIQUEOne-to-one relationship
ManyToManyField(join table)Many-to-many relationship
class Author(Model):
name = CharField(max_length=100)

class Post(Model):
title = CharField(max_length=200)
author = ForeignKey(Author, on_delete="CASCADE", related_name="posts")

class Tag(Model):
name = CharField(max_length=50)
posts = ManyToManyField(Post, through="PostTag")

See Relationships for full details.

Custom Fields

Extend Field to create your own type:

from ryx import Field

class CurrencyField(Field):
"""Stores currency codes (USD, EUR, etc.)."""

def __init__(self, **kwargs):
kwargs.setdefault("max_length", 3)
super().__init__(**kwargs)

def to_python(self, value):
if value is None:
return None
return str(value).upper()

def to_db(self, value):
return self.to_python(value)

Next Steps

Migrations — Evolve your schema → Filtering — Query your data