title: How to resolve sqlalchemy.orm.exc.UnmappedInstanceError
body: <p>I'm using Python Sqlalchemy for MYSQL db. I wrote the following script to create the class object and then add a row in the table.</p>
  
  <pre><code>from sqlalchemy import create_engine, MetaData, Table, Column, ForeignKey
  from sqlalchemy.dialects.mysql.base import VARCHAR, LONGTEXT, INTEGER
  from sqlalchemy.orm import sessionmaker
  from sqlalchemy.ext.declarative import declarative_base
  
  engine = create_engine("mysql+mysqldb://root:@localhost/mydb")
  connection = engine.connect()
  
  Session = sessionmaker(bind=engine)
  session = Session()
  Base = declarative_base()
  metadata = MetaData()
  
  class User(Base):
      __tablename__ = 'User'
      __abstract__ = True
      id = Column('id', INTEGER(display_width=11), primary_key=True, nullable=False)
      email = Column('email', VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=100), unique=True)
      password = Column('password', VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=45))
      name = Column('name', VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=100))
  
  Base.metadata.create_all(engine)
  
  add_user = User(email = "testing@testing.com",
              password = 'testing',
              name = 'testing')
  session.add(add_user)
  session.commit()
  </code></pre>
  
  <p>When I try to add to session, it throws the following errors:</p>
  
  <pre><code> AttributeError: 'User' object has no attribute '_sa_instance_state'
  
   During handling of the above exception, another exception occurred:
  
   raise exc.UnmappedInstanceError(instance)
   sqlalchemy.orm.exc.UnmappedInstanceError: Class '__main__.User' is not mapped
  </code></pre>
  
  <p>I'm new to SQLalchemy as well as OOP so can't figure out what I'm doing wrong here. Any help would be appreciated</p>