新数据库拒绝出现在 web2py appadmin 中
我正在尝试新的博客数据库设计,并且我想在 web2py 的管理界面中运行一些测试。
- 我首先从 web2py 的管理界面创建一个名为
newblog
的新 web2py 应用程序。 - 接下来,我在下面创建了
newblog/models/appdb.py
- 然后我浏览到
https://172.25.1.1/newblog/appadmin/index
的管理界面以确保数据库已创建 - 我检查了文件系统,
databases/newblog.db
有一个全新的创建时间 - 我单击 appadmin 菜单查看我的新数据库:“web2py”> “这个应用程序”> “数据库”
问题:问题是我在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),
)
I am experimenting with a new blog database design and there are some tests I would like to run in web2py's administrative interface.
- I started by creating a new web2py application called
newblog
from web2py's admin interface. - Next, I created
newblog/models/appdb.py
, below - Then I surfed to the admin interface at
https://172.25.1.1/newblog/appadmin/index
to ensure the database was created - I checked the filesystem and
databases/newblog.db
has a brand new creation time - I clicked through the appadmin menu to see my new database: "web2py" > "This App" > "Database"
Problem: The problem is I don't see it in the database admin interface for newblog
. I have seen other empty web2py databases displayed in the appadmin interface, so I don't understand why mine does not show up there.
Question: Is this expected behavior? If so, what are the minimal steps I need to take for my web2py database to show up in 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),
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来除了自定义
appdb.py
文件之外,您还有默认的db.py
文件。请注意,模型文件按字母顺序执行,因此db.py
在文件之后执行。db.py
将不同的数据库连接分配给变量db
,因此只有该数据库显示在appadmin
中。您应该为两组表使用相同的数据库,或者为两个数据库连接对象使用不同的变量。例如,在appdb.py
中,您可以这样做:blogdb = DAL('sqlite:\\newblog.db')
如果您想对所有数据库使用相同的数据库表,然后只需在第一个文件(在本例中为
appdb.py
)中定义 DAL 对象,您就可以在所有后续模型文件中引用它(不要重新定义它)。It sounds like you have the default
db.py
file in addition to your customappdb.py
file. Note, model files are executed in alphabetical order, sodb.py
is executed after your file.db.py
assigns a different database connection to the variabledb
, so only that database is showing up inappadmin
. You should either use the same database for both sets of tables, or use different variables for the two database connection objects. For example, inappdb.py
, you might do:blogdb = DAL('sqlite:\\newblog.db')
If you want to use the same database for all tables, then just define your DAL object in the first file (in this case,
appdb.py
), and you can refer to it in all subsequent model files (do not redefine it).