Mik*_*ton 2 python database web2py
我正在尝试新的博客数据库设计,我想在web2py的管理界面中运行一些测试.
newblog从web2py的管理界面调用的新web2py应用程序.newblog/models/appdb.py下面创建了https://172.25.1.1/newblog/appadmin/index以确保创建了数据库databases/newblog.db创建了一个全新的创建时间问题:问题是我在数据库管理界面中没有看到它newblog.我看到appadmin界面中显示了其他空的web2py数据库,所以我不明白为什么我的那些没有出现.
问题:这是预期的行为吗?如果是这样,我需要采取哪些最小步骤才能让我的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),
)
Run Code Online (Sandbox Code Playgroud)
听起来db.py除了自定义appdb.py文件之外,您还拥有默认文件.注意,模型文件按字母顺序db.py执行,因此在文件后执行.db.py为变量分配不同的数据库连接db,因此只显示该数据库appadmin.您应该对两组表使用相同的数据库,或者对两个数据库连接对象使用不同的变量.例如,appdb.py你可以这样做:
blogdb = DAL('sqlite:\\newblog.db')
如果要对所有表使用相同的数据库,则只需在第一个文件中定义DAL对象(在本例中为appdb.py),并且可以在所有后续模型文件中引用它(不要重新定义它).