Austin Cory Bart
Austin Cory Bart

Reputation: 2507

Web2py sessions table does not exist?

Recently after some updates to some of my models, I got this error in web2py.

Traceback (most recent call last):
  File "/Users/acbart/web2py/gluon/main.py", line 457, in wsgibase
    session._try_store_in_db(request, response)
  File "/Users/acbart/web2py/gluon/globals.py", line 1116, in _try_store_in_db
    record_id = table.insert(**dd)
  File "/Users/acbart/web2py/gluon/dal.py", line 9114, in insert
    ret =  self._db._adapter.insert(self, self._listify(fields))
  File "/Users/acbart/web2py/gluon/dal.py", line 1360, in insert
    raise e
ProgrammingError: (1146, u"Table 'runestone_dev.web2py_session_runestone' doesn't exist")

My web2py application is named runestone, and the database is named runestone_dev. I've checked the MySQL database and the table doesn't exist. But it is my understanding that this is a table that should be automatically generated for me. Anyone know what gives? It doesn't appear to be an obvious problem with my code...

Upvotes: 0

Views: 1095

Answers (2)

Alex Bender
Alex Bender

Reputation: 906

I have exactly the same error, and in my case I have solved it by doing next steps:

  • reinstall web2py
  • clone runestone project into application folder.
  • create web2py/applications/runestone/models/1.py with settings.database_uri = <your_connection_string>. Connection string should looks like postgres://username:passwd@localhost/dbname if you are using Postgres.
  • clone desired book into web2py/applications/runestone/books/
  • edit book's pavement.py file: 'dburl': 'postgresql://bmiller@localhost/runestone',. dburl should points to your database

Upvotes: 0

Anthony
Anthony

Reputation: 25536

It sounds like at some point web2py created the sessions table (and therefore the associated migrations meta-data file in the application's /databases folder), but subsequent to that, you either created/switched to a new database or dropped the table from the database. As a result, web2py thinks the table is in the database and is not attempting to re-create it.

In the application's /databases folder, look for a file with a name that matches the pattern *_web2py_session_runestone.table and delete it. This will prompt web2py to re-create the table in the database on the next request.

Upvotes: 1

Related Questions