Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nad2000 opened this issue Sep 13, 2024 · 0 comments

Comments

@nad2000
Copy link

nad2000 commented Sep 13, 2024

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,  ...);
...
@nad2000 nad2000 changed the title After update to 4.5.1 all monitor fields get altered with NOT NULL constraint After update to 4.5.1/5.0.0 all monitor fields get altered with NOT NULL constraint Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant