Opened 5 months ago

Last modified 5 months ago

#28980 new Cleanup/optimization

Make the autodetector validate the type of one-off default values

Reported by: Nikos Katsos Owned by: nobody
Component: Migrations Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


As the title says Django doesn't check the type of one-off value. Recently I had a field like this

    start_time = models.DateTimeField(editable=False)

1) I gave to the field an one-off value

>>> 0 

2) then the migration file had those operations

    operations = [
            field=models.CharField(default='TO', max_length=16),
            field=models.DateTimeField(default=0 editable=False),

when I found my error i couldn't really do anything
I changed

            field=models.DateTimeField(default=0, editable=False),


            field=models.DateTimeField(, editable=False),

so after updating my migration file, I got an error "django.db.utils.OperationalError: (1060, "Duplicate column name "outcome")".
I could neither re-migrate because the operations isn't a bunch of queries in transaction, nor create a new migration.
Only reverting to zero and apply all migrations again worked.

This has to have a workaround.

Change History (1)

comment:1 Changed 5 months ago by Tim Graham

Summary: Django doesn't check the type of one-off valueMake the autodetector validate the type of one-off default values
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization
Note: See TracTickets for help on using tickets.
Back to Top