0

I am trying to access mysql database in xampp server using flask_sqlalchemy

my code is as follows

from flask import Flask , render_template , request
from flask_sqlalchemy import SQLAlchemy


app = Flask(__name__)
app.secret_key = "secreat key"

app.config['SQLALCHEMY DATABASE_URI'] = 'mysql://root:@localhost/cust_51_stock_list'
app.config['SQLALCHEMY TRACK_MODIFICATIONS'] = False

db =   SQLAlchemy(app)

class Stocks(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    tiker = db.Column(db.String(15))
    price = db.Column(db.String(20))
    qty = db.Column(db.String(20))

    

@app.route('/')
def home():
    tkrs = Stocks.query.all()
    all_data = ['1','2','3','4','5','6','7']
    return render_template('home.html', stk_data=tkrs)

# @app.route('/getdata', methods = ['POST'])
# def send_data():
#     if request.method == 'POST':


if __name__ == "__main__":
    app.run(debug=True)

when I try to access it in html its showing error "sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table"

where I have database "cust_51_stock_list" and table "stocks"

please help

2
  • Have you created the table(s), as described in this Q&A? Commented Dec 3, 2020 at 7:49
  • yes i have created and there are some rows already Commented Dec 3, 2020 at 13:14

1 Answer 1

0

You need to create the tables in the database before you can add models to them. Use db.create_all() to do this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.