简体   繁体   English

无法在 repl.it 上的 flask_sqlalchemy 中的数据库上创建表

[英]unable to create table on database in flask_sqlalchemy on repl.it

it seems that this problem only arises when i am using flask application factory method似乎只有在我使用 flask 应用程序工厂方法时才会出现此问题

here is the link to repl, and是repl的链接,并且

here is the link to post i made asking fro help (Kindly read the comment section) 是我寻求帮助的帖子链接(请阅读评论部分)

  1. I have commented the app.run() part so that it won't start server我已经评论了app.run()部分,这样它就不会启动服务器
#!main.py l:3
#if __name__ == '__main__':
#    app.run(host='0.0.0.0')
  1. After running the repl once on the console side i typed在控制台端运行 repl 一次后,我输入了
from app.main.models import *
with app.app_context():
    db.create_all()

now in theory these line of code should create database with table defined init such that if i do Food.query.all it should return (in theory) an empty list => [] but it returns an error RuntimeError: No application found.现在理论上,这些代码行应该创建带有表定义 init 的数据库,这样如果我执行Food.query.all它应该(理论上)返回一个空列表 => []但它返回一个错误RuntimeError: No application found.

note : Kindly fork the repl you don't need an account for that just click on the fork button beside run because it might show wired when many people run it together注意:请分叉您不需要帐户的repl,只需单击运行旁边的分叉按钮,因为当很多人一起运行时它可能会显示有线

It seems that you've not commit the session & it's not the best practice to import function by *.您似乎没有提交 session 并且通过 * 导入 function 不是最佳做法。 You should specify specicfic module or Maybe you haven't insert any values in db so you are getting an empty list.您应该指定特定的模块,或者您可能没有在 db 中插入任何值,因此您得到一个空列表。 I'm not sure about this.But your solution might be in between.我不确定这一点。但您的解决方案可能介于两者之间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM