V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
shinerene
V2EX  ›  Python

Schema.sql的疑问

  •  
  •   shinerene ·
    Xiechen · 2013-05-08 16:22:02 +08:00 via iPad · 2813 次点击
    这是一个创建于 4006 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在看flask的文档 发现有个叫schema.sql的文档 请问有什么用?具体作用是干嘛的 ?能解释的清除一些吗?
    谢谢啦!
    12 条回复    1970-01-01 08:00:00 +08:00
    cloverstd
        1
    cloverstd  
       2013-05-08 20:09:54 +08:00
    创建数据库
    shinerene
        2
    shinerene  
    OP
       2013-05-08 20:47:03 +08:00
    @cloverstd 那为什么有了schema.sql之后还要有xxx.db这个文件呢 请问两个的区别在哪里?
    scarlex
        3
    scarlex  
       2013-05-08 21:18:45 +08:00
    schema.sql里面写的是创建数据库的语句
    xxx.db是由schema.sql生成的数据库吧
    xavierskip
        4
    xavierskip  
       2013-05-08 23:10:40 +08:00
    创建数据库的表结构用的呀,就是一堆sql语句,看来lz对数据库还不是很了解呀。
    cloverstd
        5
    cloverstd  
       2013-05-09 00:11:36 +08:00
    @shinerene 你看的 Flask 的教程里用的 SQLite
    你可以先去看看 http://sql.learncodethehardway.org/ 这个再看 FLask 的这个教程也不迟
    shinerene
        6
    shinerene  
    OP
       2013-05-09 08:18:26 +08:00
    @scarlex 恩 ~
    @xavierskip 恩 刚刚开始学习额 对于数据库的一些基本操作语句有了解 但是 从头到尾创建i个数据库 还是很不了解
    @cloverstd 这个教程很不错~谢谢了~
    shinerene
        7
    shinerene  
    OP
       2013-05-09 18:06:45 +08:00
    @cloverstd 还有个问题 我按照flask的tutorial 写了个很简单的app 然后可以登陆 只要不推出运行着的程序 可是每次关掉之后 再次启动就提示 没有此用户 也就是说 用户信息没有被写入数据库吗?要怎么解决这个问题?
    cloverstd
        8
    cloverstd  
       2013-05-09 18:27:41 +08:00
    @shinerene commit()
    数据修改后要 commit
    cloverstd
        9
    cloverstd  
       2013-05-09 18:28:56 +08:00
    @shinerene
    你是按照这个吗?
    def init_db():
    with closing(connect_db()) as db:
    with app.open_resource('schema.sql') as f:
    db.cursor().executescript(f.read())
    db.commit()

    如果你按照这个 tutorial 这样初始化数据库,每次都会初始一遍的。
    shinerene
        10
    shinerene  
    OP
       2013-05-09 18:37:40 +08:00
    @cloverstd 嗯嗯 对的 我就是按照这个的 请问要怎样来修改呢??
    cloverstd
        11
    cloverstd  
       2013-05-09 19:19:42 +08:00
    @shinerene 初始一遍就不要初始了
    让 init_db() 只运行一遍
    shinerene
        12
    shinerene  
    OP
       2013-05-09 22:15:26 +08:00
    @cloverstd ok!搞定了!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2848 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 07:06 · PVG 15:06 · LAX 00:06 · JFK 03:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.