Models FacebookPost and TwitterPost share an enum called types. This enum 
is correctly created when creating facebook_posts table, but when trying to 
create twitter_posts table, there is an attempt to recreate this type which 
results in an error.

    
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) type "types" 
already exists
     [SQL: "CREATE TYPE types AS ENUM ('Video', 'GIF', 'Scratch Reel', 
'Card', 'Video Card', 'Text', 'Photo', 'Shared Article', 'Reply', 'Canvas', 
'Carousel', 'Video Carousel', 'Link', 'Status')"]


This is the way I'm creating the database. I can't use 
Base.metadata.create_all, because I need to be explicit in terms of what 
tables are created

    
Engine = create_engine(db_url, echo=False)
    Campaign.__table__.create(Engine)
    SubCampaign.__table__.create(Engine)
    Creative.__table__.create(Engine)
    Hashtag.__table__.create(Engine)
    FacebookPost.__table__.create(Engine)
    TwitterPost.__table__.create(Engine)



I'm creating the enums this way:


from sqlalchemy import Enum
    types = ('Video', 'GIF', 'Scratch Reel', 'Card', 'Video Card',
             'Text', 'Photo', 'Shared Article', 'Reply', 'Canvas',
             'Carousel', 'Video Carousel', 'Link', 'Status')
    goals = ('CTR', 'ER', 'Awareness', 'CPGA')
    sources = ('Facebook', 'Twitter', 'Instagram', 'Tumblr')
    
    vars_ = locals().copy()
    for k, v in vars_.items():
        if isinstance(v, tuple):
            locals()[k] = Enum(*v, name=k)

Thanks

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to