#25417: Add a system check for an invalid default on a model field
-------------------------------------+-------------------------------------
Reporter: avorio | Owner: charettes
Type: New feature | Status: closed
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution: fixed
Keywords: decimal, | Triage Stage: Ready for
InvalidOperation, migrations | checkin
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by aidanlister):
Yeah 71ebcb8 seems naive. Trying to validate the default value causes
exceptions under certain scenarios, which means more than just a warning,
it prevents the initial migrations from being run. The default value might
only be valid after migrations are finished, e.g.:
a) dynamic default values that rely on the database, e.g.:
ref = models.CharField(unique=True, max_length=200,
default=rectification_sequence_current, blank=True)
rectification_sequence_current is a method that checks the sequence in the
database. This throws as uncaught exception that the table doesn't exist.
b) defaults that rely on a migration creating a row, e.g:
pricetier = models.ForeignKey('PriceTier', default=0)
the initial pricetier is created by the first migration, but that won't
run, because the check does a database query against a table that doesn't
exist.
--
Ticket URL: <https://code.djangoproject.com/ticket/25417#comment:25>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.19948598fbf134272bbe3b468dfaf0a2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.