title: SQLAlchemy not creating tables
body: <p>I am trying to setup a database just like in a tutorial but I am getting a programming error that a table doesn't exist when I'm trying to add a <code>User</code></p>
  
  <p>This is the file that errors (<code>database.py</code>):</p>
  
  <pre><code>from sqlalchemy import create_engine, MetaData
  from sqlalchemy.orm import scoped_session, sessionmaker
  from sqlalchemy.ext.declarative import declarative_base
  
  
  engine = create_engine(
      "mysql+pymysql://testuser:testpassword@localhost/test?charset=utf8",
      connect_args = {
          "port": 3306
      },
      echo="debug",
      echo_pool=True
  )
  
  db_session = scoped_session(
      sessionmaker(
          bind=engine,
          autocommit=False,
          autoflush=False
      )
  )
  
  Base = declarative_base()
  
  def init_db():
      import models
      Base.metadata.create_all(bind=engine)
  
      from models import User
      db_session.add(
          User(username="testuser", password_hash=b"", password_salt=b"", balance=1)
      )
      db_session.commit()
  
      print("Initialized the db")
  
  
  if __name__ == "__main__":
      init_db()
  </code></pre>
  
  <p>To init the database (create the tables) I just run the file.
  It errors when it creates the test user.</p>
  
  <p>Here is <code>models.py</code>:</p>
  
  <pre><code>from sqlalchemy import Column, Integer, Numeric, Binary, String
  from sqlalchemy.orm import relationship
  
  from database import Base
  
  
  class User(Base):
      __tablename__ = "users"
  
      id = Column(Integer, primary_key=True)
  
      username = Column(String(16), unique=True)
      password_hash = Column(Binary(32))
      password_salt = Column(Binary(32))
  
      balance = Column(Numeric(precision=65, scale=8))
  
      def __repr__(self):
          return "&lt;User(balance={})&gt;".format(balance)
  </code></pre>
  
  <p>I tried:</p>
  
  <ul>
  <li>Committing before adding users (after <code>create_all</code>)</li>
  <li>Drop existing tables from the database (although it seems like the table never gets committed)</li>
  <li><code>from models import User</code> instead of <code>import models</code> (before <code>create_all</code>)</li>
  </ul>
  
  <p>Sorry if there are so many simillar questions, I promise I scavenged for answers, but it's always silly mistakes I made sure I didn't make (or atleast the ones I saw).</p>
  
  <p>I am using MariaDB.</p>
  
  <p>Sorry for long post, many thanks in advance.</p>