sqlite3.OperationalError)没有这样的表-带huey任务队列的烧瓶

时间:2018-08-26 20:29:00

标签: python flask-sqlalchemy python-huey

enter image description here

我正在尝试使用python huey(https://github.com/coleifer/huey/blob/master/huey/api.py)来允许烧瓶使用任务队列。

我的应用程序/初始化包含:

type RangeFn = fn(&(), &()) -> bool;

struct Range {
    fun: RangeFn,
    other_field: u32,
}

impl std::fmt::Debug for Range {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
        f.debug_struct("Range")
            .field("other_field", &self.other_field)
            .finish()
    }
}

fn main() {
    let r = Range {
        fun: |_, _| true,
        other_field: 42,
    };

    println!("{:?}", r);
}

我的huey任务文件夹包含:

from flask_sqlalchemy import SQLAlchemy

mail = Mail()
db = SQLAlchemy()



def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    # not using sqlalchemy event system, hence disabling it

    config[config_name].init_app(app)

    # Set up tasking
    mail.init_app(app)
    db.init_app(app)
    ......

    return app


def create_huey_app():
    _app = Flask('huey-app')
    db.init_app(_app)

    from app.models.other_models import Postings, Accounts

    return _app

在烧瓶视图中,我有:

@my_huey.task()
def create_listing_task(messages):
    """Background task to send an email with Flask-Mail."""
    h_app = create_huey_app()
    with h_app.app_context():
        create_listing(messages)

我得到的错误是

@main.route('/selected')
def selected():

....

    res  = create_listing_task(messages)
    res(blocking=True, timeout=5)  # Block for up to 5 seconds

    return 'fin'

尽管我正在初始化flask-sqlalchemy扩展名,但该应用程序似乎找不到该表。我该如何工作?

1 个答案:

答案 0 :(得分:1)

不会自动创建表。您需要执行LocalDateTime.now(ZoneId.of("Europe/Berlin")).truncatedTo(ChronoUnit.MILLIS); 。请参见Flask-SQLAlchemy quickstart