Jump to content

Column already exists: 1060 Duplicate column name 'upvotes'


NorbertH
 Share

Recommended Posts

When using the Comments Module i get Errors at all actions that have to do whith comments, for example editing the field settings.

Session: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'upvotes'

FieldtypeComments: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'upvotes'

ProcessWire 2.5.28 dev

Right now there are no comments posted on the page yet! 

post-2434-0-84581400-1431516498_thumb.pn     

Link to comment
Share on other sites

  • 2 weeks later...

Interestingly enough, I'm getting the same error (in 2.6.0), and I'm not even making use of the comments module...

Edit: My bad, I see I do have a comments field in the template in question. That said, I don't recall adding it. But that could be my terrible memory.

Edit 2: Nope, looks like Comments and Categories was added when I upgraded to 2.6.0. Why would that happen? (This could be an error on my part, where I may have experimented with the comments module, but I really don't remember doing it because I specifically said to myself that this site doesn't need comments...)

Edited by Mike Rockett
  • Like 1
Link to comment
Share on other sites

Seeing the same issue here in 2.6.0, MySQL version 5.5.42-37.1-log.

Error is being generated by /wire/modules/Fieldtype/FieldtypeComments/FieldtypeComments.module:

if($createdVotesTable) try {
	$database->query("ALTER TABLE `$table` ADD `upvotes` $upvoteSchema");
	$database->query("ALTER TABLE `$table` ADD `downvotes` $downvoteSchema");
	$schemaVersion = 5;
} catch(Exception $e) { 
	$this->error($e->getMessage(), Notice::log); 
}

Without any deep understanding of what's happening here, I assumed it just needs to check if the columns exist before adding them, so I added some logic based on some other column-checking code I found elsewhere in PW:
 

$isUpvotes = $this->wire('database')->prepare("SHOW columns FROM `$table` LIKE 'upvotes'"); 
$isUpvotes->execute();
$isDownvotes = $this->wire('database')->prepare("SHOW columns FROM `$table` LIKE 'downvotes'"); 
$isDownvotes->execute();

if($createdVotesTable) try {
	if ($isUpvotes->rowCount() === 0) $database->query("ALTER TABLE `$table` ADD `upvotes` $upvoteSchema");
	if ($isDownvotes->rowCount() === 0) $database->query("ALTER TABLE `$table` ADD `downvotes` $downvoteSchema");
	$schemaVersion = 5;
} catch(Exception $e) { 
	$this->error($e->getMessage(), Notice::log); 
}

This seemed to work, and it reported that the FieldtypeComments schema was updated from 0 to 5 -- not sure if this the desired outcome.  The errors have stopped, although I have no clue if that's a good thing...!

Also, just tried installing FieldtypeComments on my local machine running PW 2.6.0 and MySQL 5.5.39, and it seemed to work fine without this modification.  My "fix" is probably not the right way about it, I'm guessing.

  • Like 2
Link to comment
Share on other sites

Evan, I think your solution is a good one, but it definitely leaves the question of why it's necessary on these particular installations. It's like the database changes got previously applied, but the schemaVersion stored with the $field didn't. I will add your changes, but also think it's hiding another issue that I'd like to find a way to reproduce so can determine the source of it. If anyone is able to reproduce on a fresh install, please let me know. 

  • Like 1
Link to comment
Share on other sites

@evan
Thanks, that helped me out for the moment!
 
@ryan 
Actual may version is a  2.5.28 Def that was upgraded in multiple steps to always the latest def version, i tried upgrading to 2.6 but the error was still there.  Later i downgraded using a backup as 2.6 had some other issues. (couldn't deninstall the old comments manager ) .
 
Maybe its mentionable that i echoed the  $field->schemaVersion and  it just gave me a Zero(0). I guess that schould be a 5.
 
I remember something from PHP manual :
 

try {
$error = 'Always throw this error';
throw new Exception($error);

// Code following an exception is not executed.
echo 'Never executed';

}

so maybe  $schemaVersion = 5;   is never executed as all tests fail and so its never saved ?

EDIT:

Did a few more tests and  it does not get executed.  I guess thats the reason why the error only states something about upvotes and never about downvotes as even downvotes isn't checked. 

EDIT2:

I had the Funnie Idea of simply setting $schemaVersion manual.

$schemaVersion = 5; //I ADDED THIS !

  if(((int) $field->schemaVersion) < $schemaVersion) {

   $this->message("Updating schema version of '{$field->name}' from $field->schemaVersion to $schemaVersion", Notice::log);

   $field->schemaVersion = $schemaVersion;

   $field->save();

  }
 

This led to a few little Errors where the most interesting might be :

TemplateFile: Field comments is not saveable because it is in a specific context

post-2434-0-27485500-1432642532_thumb.pn

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...