AddConstraintNotValid
Add a table constraint without enforcing validation, using PostgreSQL's NOT VALID syntax.
Attributes
| Attribute | Type | Description |
|---|---|---|
| category | [OperationCategory](../../../db/migrations/operations/base/operationcategory.md?sid=django_db_migrations_operations_base_operationcategory) = OperationCategory.ADDITION | The classification of the database operation, set to ADDITION to indicate this class performs a schema addition. |
Constructor
Signature
def AddConstraintNotValid(
model_name: string,
constraint: [CheckConstraint](../../../db/models/constraints/checkconstraint.md?sid=django_db_models_constraints_checkconstraint)
)
Parameters
| Name | Type | Description |
|---|---|---|
| model_name | string | The name of the model the constraint is being added to. |
| constraint | [CheckConstraint](../../../db/models/constraints/checkconstraint.md?sid=django_db_models_constraints_checkconstraint) | The check constraint object to be added to the table. |
Signature
def AddConstraintNotValid(
model_name: string,
constraint: [CheckConstraint](../../../db/models/constraints/checkconstraint.md?sid=django_db_models_constraints_checkconstraint)
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| model_name | string | The name of the database model to which the constraint will be applied. |
| constraint | [CheckConstraint](../../../db/models/constraints/checkconstraint.md?sid=django_db_models_constraints_checkconstraint) | The specific check constraint object to be added; must be an instance of CheckConstraint. |
Methods
describe()
@classmethod
def describe() - > string
Returns a human-readable string describing the operation for use in migration logs and console output.
Returns
| Type | Description |
|---|---|
string | A formatted string indicating the creation of a 'not valid' constraint and the target model name. |
database_forwards()
@classmethod
def database_forwards(
app_label: string,
schema_editor: [BaseDatabaseSchemaEditor](../../../db/backends/base/schema/basedatabaseschemaeditor.md?sid=django_db_backends_base_schema_basedatabaseschemaeditor),
from_state: [ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate),
to_state: [ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate)
) - > null
Executes the SQL command to add the constraint to the database using the 'NOT VALID' syntax to skip initial validation of existing rows.
Parameters
| Name | Type | Description |
|---|---|---|
| app_label | string | The label of the application the migration belongs to. |
| schema_editor | [BaseDatabaseSchemaEditor](../../../db/backends/base/schema/basedatabaseschemaeditor.md?sid=django_db_backends_base_schema_basedatabaseschemaeditor) | The database abstraction layer used to execute SQL statements. |
| from_state | [ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate) | The state of the project before the migration is applied. |
| to_state | [ProjectState](../../../db/migrations/state/projectstate.md?sid=django_db_migrations_state_projectstate) | The state of the project after the migration is applied. |
Returns
| Type | Description |
|---|---|
null | None |
migration_name_fragment()
@classmethod
def migration_name_fragment() - > string
Generates a string fragment used to automatically name the migration file containing this operation.
Returns
| Type | Description |
|---|---|
string | The base migration name fragment appended with '_not_valid'. |