title: How do I define and create a User model for use with Flask-Login?
body: <p>I am attempting to declare a User model in my flask application in order to implement login with the Flask-Login extension. From the flask documentation regarding sql alchemy there is this example which I have used for another model called employees. Here is the code:</p>
  
  <pre><code>class Employee(db.Model):
      __tablename__ = "employees"
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(200))
      title = db.Column(db.String(200))
      email = db.Column(db.String(200))
      department = db.Column(db.String(200))
  
      def __init__(self, name, title, email, department):
          self.name = name
          self.title = title
          self.email = email
          self.department = department
  
      def __repr__(self):
          return '&lt;Employee %r&gt;' % self.name
  </code></pre>
  
  <p>This is taken from this page as an exmample <a href="http://flask.pocoo.org/docs/0.10/patterns/sqlalchemy/" rel="noreferrer">Flask SQL-Alchemy Docs</a></p>
  
  <p>I am confused because I am also using alembic to run migrations so by using <code>alembic revision -m "create user table</code> I have already created a 'users' table. I created my first model's table (employees) by using the recommendation of the Flask Sql-Alchemy guide as such:</p>
  
  <pre><code>from yourapplication.database import init_db
  init_db()
  </code></pre>
  
  <p>Here is the confusion. I now need to establish a User model for authentication. How do I do this? Here is my code so far:</p>
  
  <pre><code>class User(flask_login.UserMixin):
      def __init__(self, username, password):
          self.id = username
          self.password = password
  </code></pre>
  
  <p>Notice that I have the User class inherit from <code>flask_login.Usermixin</code>. I need this in order for Flask Login to work so now its not instantiated like the Employee model from <code>db.Model</code>. But the thing is is that I created an alembic migration to establish my User model. Why am I not able to query the database. What piece of the puzzle am I missing?</p>