Web2py tries to redefine tables in line with changes in the model file
but sometimes this is not possible with sqlite. Therefore you may want
to delete the table definitions as well. If you do want a clean sheet
of paper then do this:

exclude=[]
import os
import glob
import sys
sys.path.append("c:/web2py")
from gluon import *
db = DAL('sqlite://storage.sqlite', folder='c:/web2py/applications/app/
databases', auto_import=True)

def delete():
    for tablename in db.tables[:]:
        if tablename in exclude or tablename[0:4]=="auth":
            print("keep "+tablename)
        else:
            table=db[tablename]
            try:
                print("delete "+tablename)
                filelist=glob.glob("c:/web2py/applications/app/
databases/*"+tablename+".table")
                if len(filelist)>0: os.remove(filelist[0])
                table.drop()
            except:
                print("failed to delete "+tablename)
                print(sys.exc_info())
    db.commit()
delete()

On Nov 14, 2:02 pm, DenesL <denes1...@yahoo.ca> wrote:
> Hi Archibald,
>
> if you want to clear all records from a table do:
>
>   db.table.truncate()
>
> To clear all just loop thru db.tables .
>
> db.commit() to finish.
>
> It should work for all DBs.
>
> On Nov 14, 7:56 am, Archibald Linx <archibaldl...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Thank you Bruno.
>
> > I am using SQLite.
>
> > I want to reset all the tables of my project.
>
> > Thanks,
> > Archibald
>
> > On 14 nov, 01:44, Bruno Rocha <rochacbr...@gmail.com> wrote:
>
> > > which database engine?
>
> > >http://zerp.ly/rochacbruno
> > > Em 13/11/2011 22:38, "Archibald Linx" <archibaldl...@gmail.com> escreveu:
>
> > > > Dear Web2py users,
>
> > > > How can I reset the database of my Web2py project ?
>
> > > > Thanks,
> > > > Archibald

Reply via email to