just python (no web2py) existing tables drop after define_table

36 views
Skip to first unread message

james c.

unread,
Apr 5, 2021, 7:27:41 PM4/5/21
to web2py-users
I am trying to access persistent data saved in an sqlite.db file without wiping it out.
I start an interactive session with just python and no web2py and enter the following:

>>> from pydal import DAL, Field

>>> db = DAL('sqlite://storage.sqlite', folder='home/cryptoj/venv', auto_import=True)

>>> db.define_table('persons', Field('name'))

Now I can create and save table data - after db.commit() the table is saved and I can read the table with DB Browser for SQLite. I can enter additional data from DB Browser and it too can be read in the interactive python session.

I close the terminal. I close DB Browser. Then I open DB Browser and the data is all there. Yet, when I go through the above commands, in a new session, it appears the db.define_table is dropping the existing data stored in storage.sqlite.

On the 2nd pass, if I don't define_table again there are errors and the existing data can not be read in the interactive session.

Thank you in advance for any recommendations, James.

 

Leonel Câmara

unread,
Apr 16, 2021, 8:53:34 AM4/16/21
to web2py-users
You need to always define the table so pydal knows it is there. That's just how pydal works. define_table only creates the table if it hasn't yet and migration is enabled.
Reply all
Reply to author
Forward
0 new messages