title: Storing Python 3 Enum in MySQL using SQLAlchemy
body: <p>When I try to store a <code>Animals</code> object with a field <code>species</code> containing a Python <code>Enum</code> object <code>SpeciesType.Cat</code>, I get the error</p>
  
  <blockquote>
    <p>TypeError: object of type 'VisitableType' has no len()</p>
  </blockquote>
  
  <p>What is the correct way to store a Python 3 <code>Enum</code> in MySQL using SQLAlchemy?</p>
  
  <pre><code># SQLALCHEMY CODE ########################
  
  from sqlalchemy import *
  from sqlalchemy.ext.declarative import declarative_base
  
  Base = declarative_base()
  
  class SpeciesType(Enum):
      Cat = 1
      Dog = 2
  
  
  class Animals(Base):
      __tablename__ = 'animals'
      id  = Column(String(16), primary_key=True)
      species = Column(Enum(SpeciesType))
  
  
  # REGULAR CODE ########################
  
  import enum
  
  class SpeciesType(enum.Enum):
      Cat = 1
      Dog = 2
  
  
  class MyClass:
      @property
      def session(self):
          ....
  
      def insertToDB(self):
          kitty = Animals(id='kitty', species=SpeciesType.Cat)
          self.session.add(kitty)
          self.session.commit()
  
  c = MyClass()
  c.insertToDB()
  </code></pre>
  
  <hr>
  
  <h2>Update</h2>
  
  <p>The following new error occurs after fixing the name collision between <code>sqlalchemy.enum</code> and <code>Enum.enum</code>.</p>
  
  <blockquote>
    <p>sqlalchemy.exc.StatementError: (builtins.LookupError) "SpeciesType.Cat" is not among the defined enum values [SQL: 'INSERT INTO animals (id, species) VALUES (%(id)s, %(species)s)'] [parameters: [{'species': , 'id': 'kitty'}]]</p>
  </blockquote>