Switching from SQLite to MySQL with Flask SQLAlchemy

前端 未结 2 1818
旧时难觅i
旧时难觅i 2020-12-07 09:44

I have a site that I\'ve built with Flask SQLAlchemy and SQLite, and need to switch to MySQL. I have migrated the database itself and have it running under MySQL, but

2条回答
  •  温柔的废话
    2020-12-07 10:04

    The accepted answer was correct at the time, but the syntax in the import statement has been deprecated.

    This:

    from flask.ext.sqlalchemy import SQLAlchemy
    

    Should be replaced with:

    import flask_sqlalchemy
    

    Since questions regarding database connections tend to get traffic and stay relevant for a long time, it's worth having on the record.

    The deprecation is in the Flask Version 1.0 Changelog, which actually uses this module in the example:

    flask.ext - import extensions directly by their name instead of through the flask.ext namespace. For example, import flask.ext.sqlalchemy becomes import flask_sqlalchemy.

提交回复
热议问题