Every attribute of a model, and every key, in tables. The other pages of
this chapter explain them with examples; the links lead there.
| Django | rind |
db_table | #[model(table = "…")] (required) |
a field with primary_key=True | the field id, or #[model(pk = "…")] (Primary keys) |
ordering | none on the model: a resource’s #[ordering(.., default("…"))] (Filters), or an order_by in a scope |
unique_together, UniqueConstraint | #[unique(on(a, b))] (Indexes and constraints) |
indexes, Index | #[index(on(a, b))], or #[index(name, sql)] |
constraints, CheckConstraint | #[check(name = "…", sql = "…")] |
abstract = True | rind::field_group! and #[rind::with_fields(..)] (Sharing fields) |
| a custom default manager | #[model(scoped)] and the model’s own scopes (Scopes) |
using, database routers | #[model(database = "…")] (Databases) |
help_text | the field’s doc comment |
verbose_name, verbose_name_plural | none |
get_latest_by, default_related_name, permissions | none |
| Django | rind |
null=True | Option<T> (Fields) |
blank=True | the input’s business |
max_length= | #[column(max_length = n)] |
default=, db_default= | #[column(default = "SQL")] (Column options) |
unique=True | #[column(unique)] |
db_index=True | #[column(index)] |
choices= | the input’s choices(..), or an enum (Types of your own) |
db_column= | none: the field is named as the column |
editable=False | leave the field out of the input |
auto_now, auto_now_add | the Tracking behaviour (Behaviours and hooks) |
GeneratedField | #[column(generated = "SQL")] |
| Key | Meaning |
table = "…" | the table’s name (required) |
pk = "…" | the field of the primary key, when it is not id |
manual_key | the inserts give the key: no identity |
key_name = "…" | the name of the primary key’s constraint, when it is not <table>_pkey |
tree = "…" | the column of the parent: the model is a tree |
scoped | no default query: Query::new() does not compile (Scopes) |
database = "…" | the database the table is in, by the name the application gives it |
behaviours(A, B) | what every write of the model runs on its statement |
hooks(A, B) | what every write of an object runs after it (or before a deletion), in this order |
| Key | Meaning |
max_length = 200 | the length of a text: character varying(200) |
default = "'open'" | the column’s default, in SQL |
unique, unique = "…" | the column is unique; with a name, the constraint’s name |
index, index = "…" | the column is indexed; with a name, the index’s name |
sql = "geometry(Point,4326)" | the SQL type, when rind cannot tell it |
read = "ST_AsGeoJSON({})::jsonb" | the SQL the column is read through, {} being the column |
generated = "md5(params::text)" | a generated column (GENERATED ALWAYS AS (…) STORED) |
| Rust | PostgreSQL | Needs sql = … |
i64, i32, i16 | bigint, integer, smallint | |
f64, f32 | double precision, real | |
bool | boolean | |
String | text, or character varying(n) with max_length | |
chrono::NaiveDate | date | |
chrono::DateTime<Utc> | timestamp with time zone | |
chrono::NaiveDateTime | timestamp without time zone | |
serde_json::Value | jsonb | |
rind::db::types::File | text, or character varying(n) with max_length | |
Vec<T> | T[] | |
Option<T> | T, nullable | |
Vec<u8> | bytea | yes |
rind::db::types::Decimal | numeric(p, s) | yes |
rind::db::types::Inet | inet | yes |
rind::db::geo::Point, Polygon, MultiPolygon, Geometry, Shape | PostGIS types | yes |
rind::db::types::Vector | vector(n) | yes |
rind::db::types::TsVector | tsvector | yes |
rind::db::types::EnumValue | an enumerated type | yes |
| a type of your own | any | yes (Types of your own) |
| Key | Meaning |
Target (first) | the model the key points to |
name = relation | the relation’s name, when it is not the field without _id |
reverse = relation | the relation the target gets back, as a trait to import (Relations) |
on_delete = … | cascade, set_null or restrict; without it, the deletion is refused while the row points to it |
in_code | the rule is applied by rind’s deletions, not by the database |
deferred | the key is checked at commit (DEFERRABLE INITIALLY DEFERRED) |
unindexed | no index for the key |
constraint = "…", index = "…" | the names the constraint and its index already have (Migrations) |
table = "…" (first), key = "…" | a key to a table this crate cannot name (Organising an application) |
external | with table: the table has no model in the application |
unfollowed | with table: no relation follows the key (models written from a database) |
| Attribute | Keys |
#[reverse(..)] | name, model, fk = "<column of the other table>"; forward = relation gives the other model the relation along its key (Organising an application) |
#[m2m(..)] | name, model, through = "<link table>", from = "<its column to this model>", to = "<its column to the target>" |
| Attribute | Keys |
#[index(..)] | on(columns), or sql = "…" (what follows ON <table>) with name = "…"; unique (with sql only); name = "…" |
#[unique(..)] | on(columns), name = "…", nulls_not_distinct |
#[check(..)] | name = "…" and sql = "…", both required |
| Object | Name |
| primary key | <table>_pkey |
| unique column | <table>_<column>_key |
| unique together | <table>_<col1>_<col2>_key |
| index | <table>_<columns>_idx |
| foreign key | <table>_<column>_fkey, and its index <table>_<column>_idx |
| check | the name you give |
For a model Station with a column city and a relation region:
| Item | What it is |
Station::city() | a Path<String> to the column; an integer column is a Path<i64> whatever its width, a float a Path<f64> |
Station::region() | a path to the related model, from which its columns are reached |
StationPath | the type of a path that ends at a Station; it has any, count, rows and filter for a many relation (Queries) |
STATION_REGION | the relation’s hop, <MODEL>_<RELATION>: what loaders and db.link take |
StationColumn | an enum with a variant per written column, for update |
StationDepartures, StationPathDepartures | the traits a reverse = departures on another model gives (<Target><Relation>) |
Region::subtree() and the other tree functions | only with tree (Trees) |
insert, save, update, refresh, delete, delete_cascade | the object writes |
A field whose name is a Rust keyword, r#type, is the column type and
the path Model::type_().
| Mistake | Message |
an unknown key in #[model(..)] | unknown key: expected `table`, `pk`, `tree`, `database`, `scoped`, `manual_key`, `key_name`, `behaviours` or `hooks` |
an unknown key in #[column(..)] | unknown key: expected `max_length`, `sql`, `default`, `unique`, `index`, `read` or `generated` |
a type rind does not know, without sql | cannot tell the SQL type of this field: give it, #[column(sql = "…")] |
a foreign key field not ending in _id | a foreign key field is named `<relation>_id`, or the relation is given: #[fk(Target, name = relation)] |
a column name in on(..) that does not exist | the model has no column `nope` |
Query::new() on a scoped model | `Loan` is a scoped model: it has no default query |
| a reverse relation used without its trait | no associated function or constant named `notes` found, with a hint naming the trait to import |