Opened 11 years ago

Closed 11 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: master
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


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):
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


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 Changed 11 years ago by Brian Rosner

Version: newforms-adminSVN

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 :)

comment:2 Changed 11 years ago by

Ok. Confirmed on SVN r7092. Still the same. I just thought I'll tell the truth that it wasn't tested on trunk :)

comment:3 Changed 11 years ago by mackenzie

I can also confirm this.

Also thanks for the workaround!!!

comment:4 Changed 11 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(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.

Note: See TracTickets for help on using tickets.
Back to Top