Jump to content

Fatal error: Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table


fisnik
 Share

Recommended Posts

Does anyone know why i am getting this error on some site today, no changes were made?

 

 

Error: Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table '%%.sessions' doesn't exist (in wire/core/WireDatabasePDO.php line 454)

#0 wire/core/WireDatabasePDO.php(454): PDOStatement->execute()
#1 wire/modules/Session/SessionHandlerDB/SessionHandlerDB.module(74): WireDatabasePDO->execute(Object(PDOStatement))
#2 [internal function]: SessionHandlerDB->read('vvvciffpban8u80...')
#3 wire/core/Session.php(267): session_start()
#4 Wire.php(380): Session->___init()
#5 wire/core/WireHooks.php(698): Wire->_callMethod('___init', Array)
#6 wire/core/Wire.php(442): WireHooks->runHooks(Object(Session), 'init', Array)
#7 wire/core/Session.php(166): Wire->__call('init', Array)
#8 /wire/core/Session.php(166): Session->init()
#9 public_html/w

 

Link to comment
Share on other sites

7 hours ago, fisnik said:

Session

[%%.sessions] Error: Table '%%.sessions' doesn't exist
[%%.sessions] status: Operation failed

I dont know why this happend but i also cannot create new tabel with name "sessions" on same database.

Workaround:

I did create new database, imported old one (sessions does not exist here)

then i run:

CREATE TABLE `sessions` (
  `data` mediumtext NOT NULL,
  `id` int(11) NOT NULL,
  `ip` varchar(256) NOT NULL,
  `pages_id` varchar(256) NOT NULL,
  `ts` varchar(256) NOT NULL,
  `ua` varchar(256) NOT NULL,
  `user_id` varchar(256) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 

Link to comment
Share on other sites

  • 5 years later...

I've randomly started having this issue too on some sites since upgrading to PHP8 in my local development environment (production is running PHP8 with no issues like this so far).

For all my sites it's saying '%sitename%.sessions doesn't exist in engine', when I try to manually create a table with the right schema (as shown in the post above ) it then complains there is a sessions table already... but i can't see one.

Has anyone else come across this?

Link to comment
Share on other sites

Hi @brodiefarrelloates Could it come from an outdated module? What says the stack trace? (should be in errors log)

In my PW database I don't have any "sessions" table, only a session_login_throttle.

EDIT: OK I see it comes from wire\modules\Session\SessionHandlerDB\SessionHandlerDB.module.

I have no idea when this module is triggered but you can see in source code the SQL query to create "sessions" table:
 

	public function ___install() {
		
		$table = self::dbTableName;
		$charset = $this->wire()->config->dbCharset;

		$sql = 	"CREATE TABLE `$table` (" . 
				"id CHAR(32) NOT NULL, " . 
				"user_id INT UNSIGNED NOT NULL, " . 
				"pages_id INT UNSIGNED NOT NULL, " . 
				"data MEDIUMTEXT NOT NULL, " . 
				"ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, " . 
				"ip INT UNSIGNED NOT NULL DEFAULT 0, " . 
				"ua VARCHAR(250) NOT NULL DEFAULT '', " . 
				"PRIMARY KEY (id), " . 
				"INDEX (pages_id), " . 
				"INDEX (user_id), " . 
				"INDEX (ts) " . 
				") ENGINE=InnoDB DEFAULT CHARSET=$charset";

		$this->database->query($sql); 
	}

 

  • Like 1
Link to comment
Share on other sites

I think I narrowed it down to some kind of incomplete MySQL change in my local development environment, so a rather freak occurance.

This Stack Overflow thread got me out the stuck position: https://stackoverflow.com/questions/15694168/error-tablespace-for-table-xxx-exists-please-discard-the-tablespace-before-imp

I had to delete a few 'session' table files from the MySQL directory, only2 out of 3 of the required files per table were there. So it was casuing some kind of stuck state were it couldn't setup or drop the sessions table.

All good now, thanks for your help!

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...