Jump to content

Error: Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'field_comment' doesn't exist


mcwhitey
 Share

Recommended Posts

Hi,

I'm using Processwire for a while now and I'm starting to love it more and more. I recently installed 3.x. Today I installed the native comments module but it seems that the table 'field_comment' was not created in the database. I retried to install it but without any luck. I get error messages and when I check phpMyAdmin, I can confirm that it's not there.

Here is the complete error message when I try to use the form on the front end of a page:

Error: Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'domain_db.field_comment' doesn't exist (in /home/domain/domains/domain.nl/public_html/wire/modules/Fieldtype/FieldtypeComments/FieldtypeComments.module line 358)

#0 /home/domain/domains/domain.nl/public_html/wire/modules/Fieldtype/FieldtypeComments/FieldtypeComments.module(358): PDOStatement->execute()
#1 /home/domain/domains/domain.nl/public_html/wire/modules/Fieldtype/FieldtypeComments/FieldtypeComments.module(338): ProcessWire\FieldtypeComments->commentMaintenance(Object(ProcessWire\Field))
#2 /home/domain/domains/domain.nl/public_html/wire/modules/Fieldtype/FieldtypeComments/FieldtypeComments.module(183): ProcessWire\FieldtypeComments->checkNewComment(Object(ProcessWire\Page), Object(ProcessWire\Field), Object(ProcessWire\Comment))
#3 [internal function]: ProcessWire\FieldtypeComments->___sleepValue(Object(ProcessWire\Page), Object(ProcessWire\Field), Object(ProcessWire\Com

This error message was shown because: you are logged in as a Superuser. Error has been logged. 

And this is what I get when I go to the Fieldtype that I created for comment:

 SQLSTATE[42S02]: Base table or view not found: 1146 Table 'domain_db.field_comment' doesn't exist (getNumRows)

I didn't start with a normal installation. Instead I used clsource's Ghost Clone. But I doubt that has anything to do with the errors.

Hope someone will be able to shed some light onto this. Thanks in advance :)

Link to comment
Share on other sites

  • 7 months later...

same here development 56, ver  

created field, added it to repeater, same error

 

6 minutes ago
2017-03-20 04:04:27	pwadmin	/pw/setup/field/save	SQLSTATE[42S02]: Base table or view not found: 1051 Unknown table 'expo_ch.field_url_link' (in /wire/core/Fieldtype.php line 1118)
7 minutes ago
2017-03-20 04:03:23	pwadmin	/pw/setup/field/save	SQLSTATE[42S02]: Base table or view not found: 1146 Table 'expo_ch.field_url_link' doesn't exist (in /wire/core/Fields.php line 758)
9 minutes ago
2017-03-20 04:01:46	pwadmin	/pw/page/edit/?id=1042	SQLSTATE[42S02]: Base table or view not found: 1146 Table 'expo_ch.field_url_link' doesn't exist (in /wire/core/WireDatabasePDO.php line 454)

 

Link to comment
Share on other sites

  • 1 month later...

I'm running into this too, with my Webmentions module on a fresh install (the FieldTypeWebmention I based a lot on this comments module).

Best I can tell, the issue seems to be that when you add a field, getDatabaseSchema is called for the first time. Since there is no $field->schemaVersion set at that point, it tries to run the first ALTER TABLE query before the field's table has been created.

Update:

I think I've found a solution. In getDatabaseSchema I first set a boolean:

$table_exists = in_array($field->getTable(), $this->database->getTables());

Then any schema upgrades can be inside an if/else conditional:
 

if ( $table_exists )
{

	# update to schema version 1
	if ( $current_schema_version < 1 )
	{
		# perform schema updates
	}

}
else
{
	$field->schemaVersion = self::SCHEMA_VERSION;
	$field->save();
}

I'm also tracking the current schema version in the class constant SCHEMA_VERSION.

Hopefully this helps other developers. Feedback is welcome!

Edited by gRegor
Added my current solution
  • Like 2
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

×
×
  • Create New...