【问题标题】:How do I reset my Web2Py application?如何重置我的 Web2Py 应用程序?
【发布时间】:2012-02-19 15:29:06
【问题描述】:

我删除了我的 Web2Py 应用程序中的所有目录,除了控制器、模型、视图和静态文件,以尝试重置我的应用程序,因为我对我的数据库结构进行了一些更改,并且认为迁移太麻烦了一个数据库几乎为空的新应用。

现在我在控制台中收到一个错误,提示 web2py 无法打开数据库文件。网络界面给了我一张未知的票。

这是来自控制台的消息:

DEBUG: connect attempt 4, connection error: Traceback (most recent call last):   File "E:\Programming\Python\web2py\gluon\dal.py", line 4736, in __init__
    self._adapter = ADAPTERS[self._dbname](*args)   File "E:\Programming\Python\web2py\gluon\dal.py", line 1655, in __init__
    self.pool_connection(connect)   File "E:\Programming\Python\web2py\gluon\dal.py", line 444, in pool_connection

    self.connection = f()   File "E:\Programming\Python\web2py\gluon\dal.py", line 1654, in connect
    return self.driver.Connection(dbpath, **driver_args) OperationalError: unable to open database file ERROR:web2py:Traceback (most recent call last):   File "E:\Programming\Python\web2py\gluon\restricted.py", line 204, in restrict ed
    exec ccode in environment   File "E:/Programming/Python/web2py/applications/vote_up\compiled\models\db.py" , line 14, in <module>   File "E:\Programming\Python\web2py\gluon\dal.py", line 4749, in __init__
    raise RuntimeError, "Failure to connect, tried %d times:\n%s" % (attempts, t b) RuntimeError: Failure to connect, tried 5 times: Traceback (most recent call last):   File "E:\Programming\Python\web2py\gluon\dal.py", line 4736, in __init__
    self._adapter = ADAPTERS[self._dbname](*args)   File "E:\Programming\Python\web2py\gluon\dal.py", line 1655, in __init__
    self.pool_connection(connect)   File "E:\Programming\Python\web2py\gluon\dal.py", line 444, in pool_connection

    self.connection = f()   File "E:\Programming\Python\web2py\gluon\dal.py", line 1654, in connect
    return self.driver.Connection(dbpath, **driver_args) OperationalError: unable to open database file

代码可在GitHub获取。

如何让 Web2Py 将其视为一个全新的应用程序?

【问题讨论】:

    标签: web2py


    【解决方案1】:

    我通常会这样做

    1. 使用管理界面创建一个新应用。
    2. 将我的控制器、模型、视图和静态文件复制到新应用程序中。

    【讨论】:

    • 谢谢@David,这就是我最终做的事情......但也许有更好的方法来做同样的事情,因为每次我们都必须重命名我们的应用程序。此外,如果知道另一种更改数据库结构的方法而不是重置应用程序,那就太好了。
    • 除了更改模型之外,您无需更改数据库结构。迁移是自动的。如果你想避免migrations,你可以清除你的数据库目录(如果你使用的是sqlite),web2py 将从头开始创建数据库。
    • 好吧,我已经重命名了表中的一个字段,但是当我尝试访问它时,我收到一条错误消息,说没有这样的字段...删除目录也是给我这个错误的原因我之前提到过一张不知名的票。
    • @Sathvik 删除 just 数据库目录的 contents 应该没问题。然后 web2py 将从头开始创建一个空数据库。
    • 请更新您的答案,以便将来对其他人有所帮助。谢谢
    猜你喜欢
    • 2013-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多