12
from sqlalchemy import *
from migrate import *

meta = MetaData()
race_enums = ('asian','mideastern','black','nativeamerican','indian','pacific','hispanic','white','other');
profiles_profiles = Table(
    'profiles_profiles', meta,
    Column('id', Integer, primary_key = True),
    Column('user_id', Integer, nullable=False, unique=True),
    Column('race', Enum, race_enums),
    Column('summary', Text, nullable= True),
    Column('my_life', Text, nullable= True),
    Column('to_do', Text, nullable= True),
    Column('favs', Text, nullable= True),
    Column('created_at', DateTime, nullable=True),
    Column('updated_at', DateTime, nullable=True)
)

def upgrade(migrate_engine):
    meta.bind = migrate_engine
    profiles_profiles.create()
    pass

def downgrade(migrate_engine):
    meta.bind = migrate_engine
    profiles_profiles.drop()
    pass

When I manage.py upgrade this, I get this error:

AttributeError: 'tuple' object has no attribute '_set_parent_with_dispatch'

1 Answer 1

28

You need pass race_enum as an argument for Enum, not Column

You can either pass in your tuple as whole

Column('race', Enum('asian','mideastern','black','nativeamerican','indian','pacific','hispanic','white','other'))

or use * to unpack race_enums:

Column('race', Enum(*race_enums))
Sign up to request clarification or add additional context in comments.

3 Comments

I'm having trouble setting the Enum value in a similar situation. How would you set the value of race for the profiles_profiles table? Does it simply take a string?
@TonyH I am not quite sure what you mean by "set the value"
I believe he means insert a record. @Wondercricket

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.