新数据库拒绝显示在web2py appadmin



我正在尝试一种新的博客数据库设计,我想在web2py的管理界面中运行一些测试。

  • 我首先从web2py的管理界面创建了一个新的web2py应用程序newblog。接下来,我在
  • 下面创建newblog/models/appdb.py
  • 然后我在https://172.25.1.1/newblog/appadmin/index冲浪到管理界面,以确保数据库被创建
  • 我检查了文件系统,databases/newblog.db有一个全新的创建时间
  • 我点击appadmin菜单,看到我的新数据库:"web2py">"这个应用程序">"数据库"

问题:问题是我没有在newblog的数据库管理界面中看到它。我已经看到其他空的web2py数据库显示在appadmin界面,所以我不明白为什么我的没有显示在那里。

问题:这是预期的行为吗?如果是这样,我需要采取哪些最小步骤才能使我的web2py数据库显示在appadmin中?

"""
newblog/models/appdb.py
"""
def build_new_table():
    return dict({'ugly_dict': 42})
db = DAL('sqlite://newblog.db')
## Build a table of tables, by the type of table (i.e. post, code, etc)
db.define_table('db_type',
    Field('name', length=32, notnull=True, unique=True,
        comment="Name of the database table"),
    #IS_IN_DB(db, 'db.%s.name' % db.db_type.name)),
    Field('database_pointer', notnull=True, unique=True,
        compute=build_new_table(),
        comment="Reference to the database table identified by 'name'",
        ),
    )
## Define tags for the database items
db.define_table('tags',
    Field('name', length=32, notnull=True, unique=True),
    )

听起来除了自定义的appdb.py文件之外,还有默认的db.py文件。注意,模型文件是按字母顺序执行的,所以db.py在文件之后执行。db.py将一个不同的数据库连接分配给变量db,因此只有该数据库显示在appadmin中。您应该对两组表使用相同的数据库,或者对两个数据库连接对象使用不同的变量。例如,在appdb.py中,您可以这样做:

blogdb = DAL('sqlite:\newblog.db')

如果您想对所有表使用相同的数据库,那么只需在第一个文件中定义您的DAL对象(在本例中为appdb.py),然后您可以在所有后续模型文件中引用它(不要重新定义它)。

最新更新