constraints
constraints
Constraint and index-specific invariants.
ForeignKeyColumnsExist
Bases: ComparisonBInvariant
Verify foreign key columns exist for relationship fields.
Django creates foreign key columns with '_id' suffix. This invariant checks that these columns exist when expected.
name
property
description
property
check(expected_schema, actual_schema)
NoOrphanedForeignKeys
Bases: ComparisonBInvariant
Verify no foreign key columns exist without corresponding tables.
This checks that tables referenced by foreign keys actually exist. Note: This is a heuristic check based on column naming patterns.
name
property
description
property
check(expected_schema, actual_schema)
PrimaryKeyExists
Bases: ComparisonBInvariant
Verify each table has a primary key column.
This checks that tables have an 'id' column which is typically the primary key in Django models.
name
property
description
property
check(expected_schema, actual_schema)
UniqueConstraintHint
Bases: ComparisonBInvariant
Provide hints about potential unique constraint issues.
This is a placeholder for future unique constraint checking. Currently, it just checks for common patterns that suggest unique constraints should exist.
name
property
description
property
check(expected_schema, actual_schema)
AllExpectedIndexesExist
Bases: ComparisonBInvariant
Verify that all indexes defined in migrations exist in the actual database.
name
property
description
property
check(expected_schema, actual_schema)
AllExpectedConstraintsExist
Bases: ComparisonBInvariant
Verify that all constraints defined in migrations exist in the actual database.
name
property
description
property
check(expected_schema, actual_schema)
NoUnexpectedIndexes
Bases: ComparisonBInvariant
Verify no indexes exist in the database that aren't defined in migrations.
Reports WARNING because Django also creates implicit indexes (e.g. for ForeignKey columns) that are not tracked via AddIndex operations. Users should review violations rather than treating them all as hard errors.
name
property
description
property
check(expected_schema, actual_schema)
NoUnexpectedConstraints
Bases: ComparisonBInvariant
Verify no constraints exist in the database that aren't defined in migrations.
Reports WARNING because Django creates implicit unique constraints for fields with unique=True and unique_together, which are not tracked via AddConstraint operations. Users should review violations rather than treating them all as hard errors.