I want to connect to MySQL database using Flask. Below is my code:
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'admin'
app.config['MYSQL_PASSWORD'] = '********'
app.config['MYSQL_DB'] = 'abc'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://admin:********@localhost/abc'
api = Api(app)
db = SQLAlchemy(app)
ma = Marshmallow(app)
db.create_all()
class Video(db.Model):
id = db.Column(db.Integer, primary_key=True)
videoid = db.Column(db.String(80), unique=True)
video_timestamp = db.Column(db.Integer, unique=True)
def __init__(self, videoid, video_timestamp):
self.videoid = videoid
self.video_timestamp = video_timestamp
and I met this error:
sqlalchemy.exc.ProgrammingError: (pymysql.err.ProgrammingError) (1146, "Table 'abc.video' doesn't exist") [SQL: 'SELECT video.id AS video_id, video.videoid AS video_videoid, video.video_timestamp AS video_video_timestamp \nFROM video']
I know how to connect to SQLite database, but it seems difficult to connect to MySQL database?
Anyone can help me, please?
db.create_all()before theVideomodel is declared?from my_app import dbbut it doesn't work