Opened 17 years ago
Closed 17 years ago
#6556 closed (fixed)
Custom subclass of models.CharField does not appear in the CREATE SQL
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If I subclass models.CharField (without overwriting anything) it seems to work perfectly but the field is not created on syncdb anymore. Explicitly defining get_internal_type() fixes this.
That's the field (working)
class Event(models.Model): urania_event_id = models.CharField("foo", max_length=4, unique_for_year="time")
Subclassed without changing anything.
class UraniaEventID(models.CharField): pass class Event(models.Model): urania_event_id = UraniaEventID("foo", max_length=4, unique_for_year="time")
Effect: 'urania_event_id' does not appear in CREATE SQL anymore
Workaround:
class UraniaEventID(models.CharField): def get_internal_type(self): return "CharField" class Event(models.Model): urania_event_id = UraniaEventID("foo", max_length=4, unique_for_year="time")
Change History (4)
comment:1 by , 17 years ago
Version: | newforms-admin → SVN |
---|
comment:2 by , 17 years ago
Ok. Confirmed on SVN r7092. Still the same. I just thought I'll tell the truth that it wasn't tested on trunk :)
comment:4 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In [7133]) It makes sense that when you subclass an existing model field, you're often
going to be using the same database column type. Made that properly
inheritable (previously it was using the class name), at the cost of a little
more verboseness.
This is very slightly backwards incompatible (for subclasses of existing fields
that were relying on the old default).
Fixed #6556.
Whether or not this is a problem, I highly doubt this is specific to newforms-admin as it has NOTHING to do with the database wrapper. Please verify this is the case on SVN, regardless if this is an actual problem or not. If I am wrong, please do correct me, but with some solid evidence :)