0

I run this application but it is not connecting to MySQL database. I am using Python version 3.7.4 and Flask-SQLAlchemy version 2.4.1

from flask import Flask , render_template, request

from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)       
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:@localhost/codingthunder'
db = SQLAlchemy(app)


class Contacts(db.Model):               **# Table in database = contacts**

    sno = db.Column(db.Integer , primary_key=True)   **# sno = Primary key** 

    name = db.Column(db.String(80),unique=False, nullable=False)

    def __repr__(self):
        return f"<User> {self.name}"

@app.route("/")             #defining route
def home():
    return render_template("/index.html")

@app.route("/contact" , methods = ['GET','POST'])     

def contact():
    if request.method == 'POST':
        entry = Contacts(name = "ashfaq")
        db.session.add(entry)
        db.session.commit()
    return render_template("contact.html")        

app.run(debug = True)           

And the Error is ModuleNotFoundError: No module named 'MySQLdb'

  • Doesn't your own, bolded, error answer your own question? Clearly you must be familiar with installing python modules – roganjosh Nov 19 '19 at 23:24

1 Answers1

2

You can try this: pip install pymysql

This command will try to install the package: pymysql , which was missing in your programm before.

PV8
  • 5,799
  • 7
  • 43
  • 87