Skip to content

After update to 4.5.1/5.0.0 all monitor fields get altered with NOT NULL constraint #631

Description

@nad2000

Problem

After the upgrade to 4.5.1 all monitor fields get altered with NOT NULL constraint even though both null=True and blank=True are present and the model was not changed.

Expected that either no change/migrations are generated or NOT NULL doesn't get added.

Environment

  • Django Model Utils version: both 4.5.1 and 5.0,0
  • Django version: 5.1
  • Python version: 3.11
  • Other libraries used, if any: -

Code examples

models.py

...
# the field spec wasn't changed updating to the current version
tac_accepted_at = MonitorField(
    monitor="state",
    when=["tac_accepted"],
    null=True,
    default=None,
    blank=True,
)
...

field alter added to the next migration after the update:

...
migrations.AlterField(
    model_name="application",
    name="tac_accepted_at",
    field=model_utils.fields.MonitorField(
        blank=True,
        default=None,
        monitor="state",
        null=True,
        when={"tac_accepted"},
    ),
),
...

the migration fails with: django.db.utils.IntegrityError: NOT NULL constraint failed: new__application.tac_accepted_at

anage.py sqlmigrate ...

sqlmigrated produced SQL with NOT NULL constraint and fails to copy the data from the table.
The available workaround is to comment or delete the field alterations from the migrations.

...
CREATE TABLE "new__application" ( ... "tac_accepted_at" datetime NOT NULL,  ...);
...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions