On Dec 15, 2013, at 4:16 AM, Hồng Quân Nguyễn <[email protected]> wrote:
> Hi all,
>
> Assume that I have this model
>
> class ModelA:
> gender = Column(Enum('male', 'female', name='gender_type'))
>
> and in another ModelB, I want to reuse this gender_type Enum, how should I
> reuse, because if I write
>
> class ModelB:
> gender = Column(Enum('male', 'female', name='gender_type'))
>
> I will get error about "conflict when creating new Enum type”.
assuming you’re on Postgresql, where there is a specific type created on the
backend.
Start like this:
gender_type = Enum(‘male’, ‘female’, name=‘gender_type’)
then any number of column objects can use it:
Column(gender_type)
or start with the PG type:
from sqlalchemy.dialects.postgresql import ENUM
gender_type = ENUM(‘male’, ‘female’, name=‘gender_type’)
then additional columns can use the same type, but create_type=False:
Column(ENUM(‘male’, ‘female’, name=‘gender_type’, create_type=False))
unfortunately the “create_type” argument is not on the base Enum type right now
(looking into adding that).
>
> I tried this recipe http://techspot.zzzeek.org/2011/01/14/the-enum-recipe/
> but it seems old and doesn't work: I got warning about null IN-predicate, as
> well as get error 500 when using with Flask-Admin :-(
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" 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].
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.
signature.asc
Description: Message signed with OpenPGP using GPGMail
