Flaskr-flask 教程 数据库混乱?
http://flask.pocoo.org/docs/tutorial/dbinit/- Flask教程的这一步是这样写的——
这样的模式可以通过将 schema.sql 文件通过管道传输到 sqlite3 命令中来创建,如下所示:
<块引用>sqlite3 /tmp/flaskr.db <架构.sql
这样做的缺点是它需要安装 sqlite3 命令,但并非每个系统都需要安装 sqlite3 命令。此外,还必须提供数据库的路径,这会留下一些容易出错的地方。最好向应用程序添加一个为您初始化数据库的函数。
管道 schema.sql 文件和添加函数两者都是必要的还是替代方案?
http://flask.pocoo.org/docs/tutorial/dbinit/- In this step of the Flask tutorial is written-
Such a schema can be created by piping the schema.sql file into the sqlite3 command as follows:
sqlite3 /tmp/flaskr.db < schema.sql
The downside of this is that it requires the sqlite3 command to be installed which is not necessarily the case on every system. Also one has to provide the path to the database there which leaves some place for errors. It’s a good idea to add a function that initializes the database for you to the application.
Are both, piping the schema.sql file and adding a function, necessary or are they alternatives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
他们是替代品。我认为作者建议,当您遵循本教程时,通过管道传输 sql 是可以的,但是当您编写自己的实际应用程序时,您应该添加一个函数并使用它。
They're alternatives. I think the author suggests that when you're following the tutorial, piping the sql is okay, but when you're writing your own real applications, you should add a function and use that instead.