title: flask-SQLAlchemy OperationalError: (sqlite3.OperationalError) no such table
body: <p>myapp.py</p>
  
  <pre><code>from flask import Flask
  app = Flask(__name__)
  app.config.from_object('config')
  from view import *
  if __name__ == '__main__':
      app.run(debug=True)
  </code></pre>
  
  <p>view.py</p>
  
  <pre><code>from flask import render_template
  from myapp import app
  from model import db,User
  @app.route('/test')
  def test():
      aaa=User(username='admin',password='admin',email='xxx')
      db.session.add(aaa)
      db.session.commit()
      return 'commit user'
  </code></pre>
  
  <p>config.py</p>
  
  <pre><code>SQLALCHEMY_DATABASE_URL="mysql://%s:%s@%s/%s" % ('root', 'root', '127.0.0.1:3306', 'blog')
  </code></pre>
  
  <p>model.py</p>
  
  <pre><code>from flask.ext.sqlalchemy import SQLAlchemy
  from myapp import app
  db=SQLAlchemy(app)
  class User(db.Model):
      __tablename__='user'
      id=db.Column(db.Integer,primary_key=True,unique=True)
      username=db.Column(db.String(45))
      password=db.Column(db.String(45))
      email=db.Column(db.String(45))
      def __repr__(self):
          return '&lt;User %r&gt;' % self.username
  </code></pre>
  
  <p>run myapp.py and visit <code>/test</code>:</p>
  
  <blockquote>
    <p>OperationalError: (sqlite3.OperationalError) no such table user</p>
  </blockquote>
  
  <p>I have already create database and table</p>