Schema.sql的疑问 - V2EX
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 3284 次点击
    这是一个创建于 4615 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在看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生成的数据库吧
    C0VN
        4
    C0VN  
      &bsp;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     Solana     2697 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 26ms UTC 11:54 PVG 19:54 LAX 03:54 JFK 06:54
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86