title: Flask - SQLAlchemy OperationalError
body: <p>I've come into the following error:</p>
  
  <pre><code>sqlalchemy.exc.OperationalError
  OperationalError: (OperationalError) no such table: user u'SELECT user.id AS user_id, user.name AS user_name, user.password AS user_password \nFROM user \nWHERE user.id = ?' (1,)
  </code></pre>
  
  <p>I'm not sure how to debug this but I think it must be coming because its not loading the db file that I already generated using my models.py file. I've loaded that db file and made sure that the users table exists, and it does with data, but I can't figure out how to connect my flask application to the database.</p>
  
  <p>Here's my models.py that I ran beforehand to generate the tables (I haven't included the declarations above it):</p>
  
  <pre><code>from datetime import datetime
  import os
  from sqlalchemy import Column, ForeignKey
  from sqlalchemy import Boolean, DateTime, Integer, String, Text
  from sqlalchemy.orm import relationship, synonym, backref
  
  from sqlalchemy.ext.declarative import declarative_base
  
  Base = declarative_base()
  
  
  """ User """
  class User(Base):
      __tablename__ = 'user'
      id = Column(Integer, primary_key=True)
      name = Column(String(200))
      password = Column(String(100))
  
      def __init__(self, name, password):
          self.name = name
          self.password = password
  
      def __repr__(self):
          return '&lt;User %r&gt;' % self.name
  if __name__ == '__main__':
      from datetime import timedelta
  
      from sqlalchemy import create_engine
      from sqlalchemy.orm import sessionmaker
  
      PWD = os.path.abspath(os.curdir)
  
      engine = create_engine('sqlite:///{}/arkaios.db'.format(PWD), echo=True)
  
      Base.metadata.create_all(engine)
      Session = sessionmaker(bind=engine)
      session = Session()
  
      # Add a sample user
      user = User(name='Philip House', password="test")
      session.add(user)
      session.commit()
  </code></pre>
  
  <p>Here's app.py:</p>
  
  <pre><code>from flask import Flask
  from flask.ext.sqlalchemy import SQLAlchemy
  from flask import render_template
  
  from arkaios.models import Base, User
  from arkaios import config
  
  app = Flask(__name__)
  app.config.from_object(config)
  
  db = SQLAlchemy(app)
  db.Model = Base
  
  @app.route('/admin/large-group')
  def largeGroupOverview():
      user = db.session.query(User).filter_by(id=1)
      return render_template('largegroup/overview.html', user=user)
  
  @app.route('/admin/large-group/&lt;int:event_id&gt;')
  def largeGroupAttendance(event_id):
      return render_template('largegroup/attendance.html')
  
  @app.route('/focus')
  def largegroup():
      return 'Focus work'
  </code></pre>
  
  <p>And finally, app.py refers to config.py which is below:</p>
  
  <pre><code>import os
  PWD = os.path.abspath(os.curdir)
  
  DEBUG=True
  SQLALCHEMY_DATABASE_URI = 'sqlite:///{}/arkaios.db'.format(PWD)
  SECRET_KEY = 'thisissecret'
  SESSION_PROTECTION = 'strong'
  </code></pre>
  
  <p>I can post the stack trace as well if need be! There must be something missing conceptually about how I'm thinking about how to connect Flask and SQLAlchemy, but I can't figure it out.</p>
  
  <p>Thanks for any help :)</p>