title: (sqlite3.OperationalError) table transactions has no column - Python
body: <p>I'm taking an online course that requires me to build a stock trading website in Python and sqlite. I am getting the following error:</p>
  
  <pre><code>sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) table 
  transactions has no column named purchase [SQL: "INSERT INTO 
  transactions (username, symbol, price, quantity, purchase, timestamp) 
  VALUES ('Ari', 'ZG', 40.39, 5, 201.95, '2017-12-13 03:58:52.905863');"]
  </code></pre>
  
  <p>If you look at my code below for updating the user's transaction history, you will see that I'm adding the purchase variable to the SQL query which I also have as a column in my database.</p>
  
  <pre><code>from cs50 import SQL
  from flask import Flask, flash, redirect, render_template, request, session, url_for
  from flask_session import Session
  from passlib.apps import custom_app_context as pwd_context
  from tempfile import mkdtemp
  from datetime import datetime
  
  from helpers import *
  
  # configure application
  app = Flask(__name__)
  
  # ensure responses aren't cached
  if app.config["DEBUG"]:
      @app.after_request
      def after_request(response):
          response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
          response.headers["Expires"] = 0
          response.headers["Pragma"] = "no-cache"
          return response
  
  # custom filter
  app.jinja_env.filters["usd"] = usd
  
  # configure session to use filesystem (instead of signed cookies)
  app.config["SESSION_FILE_DIR"] = mkdtemp()
  app.config["SESSION_PERMANENT"] = False
  app.config["SESSION_TYPE"] = "filesystem"
  Session(app)
  
  # configure CS50 Library to use SQLite database
  db = SQL("sqlite:///finance.db")
  
  @app.route("/")
  @login_required
  def index():
      return apology("TODO")
  
  @app.route("/buy", methods=["GET", "POST"])
  @login_required
  def buy():
      """Buy shares of stock."""
  
      # if user reached route via POST (as by submitting a form via POST)
      if request.method == "GET":
          return render_template("buy.html")
      else:
          # ensure user entered a symbol and shares
          symbol = request.form.get("symbol")
          shares = request.form.get("shares")
          if not symbol or not shares:
              return apology("Must input stock ticker and shares")
  
          # check to make sure stock is real
          stock = lookup(request.form.get("symbol"))
          if not stock:
              return apology("Stock does not exist")
  
          # make sure user inputs valid number of shares
          shares = int(shares)
          if shares &lt;= 0:
              return apology("Shares must be positive integer")
  
          # select user's cash balance
          rows = db.execute("SELECT * FROM users WHERE id = :id", id=session["user_id"])
          cash = float(rows[0]["cash"])
  
          # total cost of purchase
          purchase = float(stock["price"]*float(shares))
  
          # does user have enough cash?
          if cash &lt; purchase:
              return apology("You don't have enough money")
  
          # update user cash
          db.execute("UPDATE users SET cash = cash - :purchase WHERE id = :id;", \
                      purchase=purchase, id=session["user_id"])
  
          # update user's transaction history
          db.execute("INSERT INTO transactions (username, symbol, price, quantity, purchase, timestamp) \
                      VALUES (:username, :symbol, :price, :quantity, :purchase, :timestamp);", \
                      username=rows[0]["username"], symbol=stock["symbol"], price=float(stock["price"]), \
                      quantity=shares, purchase=purchase, timestamp=str(datetime.now()))
  
          # return to index
          return redirect(url_for("index"))
  </code></pre>
  
  <p>Here is an image of the structure of my transaction database:</p>
  
  <p><a href="https://i.stack.imgur.com/C3cX6.png" rel="nofollow noreferrer">SQL transactions structure</a></p>
  
  <p>Can you please help me figure out what I'm doing wrong?</p>
  
  <p>Thanks in advance!</p>