On Wed, Sep 24, 2008 at 12:52 PM, J Cook <[EMAIL PROTECTED]> wrote:

>
> I have a legacy database with a table that has many ENUM and SET fields
> - it seems that Django's models cannot handle these field types - or can
> they? I would rather not modify the table if I can get it to work as is.
>  Is this what CommaSeparatedIntegerField is for?
>
> Google has not been my friend since I cannot really find anything with
> Django MySQL ENUM and SET fields that explains one way or the other.
> Maybe this should be addressed on
> http://docs.djangoproject.com/en/dev/ref/databases/ so it could help
> others with this problem.
>

I too started with a legacy MySQL database that uses ENUM and SET fields.

ENUM is easy, in the Django model just use a CharField with choices (
http://docs.djangoproject.com/en/dev/topics/db/models/#field-options) set to
match your possible values.  (Though there is no help here provided by the
introspection of inspectdb, so you have to set this up manually.)

SET as I recall required a little more work.  It's also a CharField, but
required some translation from the comma-delimited string value passed
to/from the database layer to the Python set type I wanted to use for
manipulating the data in my Python code.  If I were writing the code today
I'd probably look into creating a custom field (
http://docs.djangoproject.com/en/dev/howto/custom-model-fields/) for a set,
but back when I had to do this it was not so easy to write custom fields, so
I did not go that route (and I have not had to revisit the code, so it stays
as originally written despite there now maybe being a better way to do
it...if it's not broken I'm not inclined to 'fix' it).

You definitely should not have to modify the table (if Django had required
that I do that, I would not have used Django).

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to