2

I've got a few issues with a site but I'll try to separate in case they're not related.

Firstly I keep getting "Failed task - Deleting stale template caches".

I've looked in the logs and some messages include:

Encountered an error running task 3 (DeleteStaleTemplateCaches), step 156 of 166: An exception was thrown: CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'dateCreated' in order clause is ambiguous

and

CDbCommand::fetchAll() failed: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'dateCreated' in order clause is ambiguous. The SQL statement executed was: SELECT elements.id, entries.sectionId, entries.typeId, entries.authorId, entries.postDate, entries.expiryDate

1 Answer 1

2

Similar to How to fix "ambiguous" column error generated when DeleteStaleTemplateCaches is run?

But somewhere, in one of your templates that are using the {% cache %} tag, you're ordering by dateCreated in your template and it should be elements.dateCreated.

The {% cache %} tag has already picked up the invalid Twig code and cached it to the database so whenever the DeleteStaleTemplateCaches task tries to run, it trips up on the invalid Twig.

So after you fix the original error, you'll want to clear your template caches using the Clear Caches tool under settings in the control panel to purge the invalid cached code as well.

3
  • Thanks Brad. Out of curiosity, why does this only apply to dateCreated ? Commented Oct 27, 2016 at 17:32
  • Just a side-effect of the way we build the main elements query on the back-end. Not an issue anymore on the upcoming Craft 3.
    – Brad Bell
    Commented Oct 27, 2016 at 18:05
  • Okay, good to know :) Commented Oct 27, 2016 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.