我想删除数据库中的所有表db
。我所做的就是遍历db.tables
并一一删除它们。但是,某些表会被忽略,因此不会被删除。然后我改为drop
,truncate
每个表都被截断。那么,有什么问题drop
呢?
以下是代码:
控制器/admin.py:
def olddo_remove():
response.view = 'admin/do_remove.html'
l = []
k = []
for table_name in db.tables:
l.append(table_name)
db[table_name].drop()
#db[table_name].truncate()
return locals()
def do_remove():
l = []
k = []
for table_name in db.tables:
l.append(table_name)
for table_name in l:
k.append(table_name)
db[table_name].drop()
return locals()
意见/管理/do_remove.html:
{{=l}}<br />{{=k}}
当我访问 admin/olddo_remove 时,我得到
['auth_user', 'auth_membership', 'auth_event', 'client', 'data']
[]
当我访问 admin/do_remove 时,我得到
['auth_user', 'auth_group', 'auth_membership', 'auth_permission', 'auth_event', 'auth_cas', 'client', 'product', 'data']
['auth_user', 'auth_group', 'auth_membership', 'auth_permission', 'auth_event', 'auth_cas', 'client', 'product', 'data']
如果我在 olddo_remove 中更改为drop
,truncate
输出将是
['auth_user', 'auth_group', 'auth_membership', 'auth_permission', 'auth_event', 'auth_cas', 'client', 'product', 'data']
[]
为什么?怎么了?
这太疯狂了!
def test():
response.view = 'admin/do_remove.html'
l = db.tables
k = []
for table_name in l:
k.append(table_name)
db[table_name].drop()
return locals()
输出:
['auth_group', 'auth_permission', 'auth_cas', 'product']
['auth_user', 'auth_membership', 'auth_event', 'client', 'data']
并且只删除了第二行的表格。