<p>OK, I found the answer to this. Here is the <a href="https://craftcms.stackexchange.com/questions/17458/failed-task-and-various-errors-in-logs">correct answer.</a></p>

<p>Basically change <code>dateCreated</code> to <code>elements.dateCreated</code> in my template.</p>

CC BY-SA 4.0
2018-11-03T22:54:29.333Z
2018-11-03T22:54:29.333Z
hvs
<p>For some of the extremely static content on my site, I use caching to prevent multiple db queries during every single load. I also have multiple locale on my site with custom cache key names. The actual execution of cache is running perfectly at the moment on all the locales. </p>

<p>However, when I make changes to any entry which has cache enabled, I get <em>stale template delete failed</em> error. When I take look at the actual MySQL table, I see that the requisite cache row is deleted from the table upon making changes to an entry. So I don't quite understand why this error shows up.</p>

<p>Here is a typical cache directive I used in my templates</p>

<pre><code> {% cache globally using key  "www-features" for 24 hours %}
</code></pre>

<p>When I look at the runtime logs, I see following error which I am assuming it to be associated with this problem</p>

<blockquote>
  <p>2018/11/03 19:10:42 [error] [application] Encountered an error running task 17 (DeleteStaleTemplateCaches), step 13 of 29: An exception was thrown: 
  CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'dateCreated' in order clause is ambiguous. 
  The SQL statement executed was: 
  SELECT <code>elements</code>.<code>id</code>, <code>entries</code>.<code>sectionId</code>, <code>entries</code>.<code>typeId</code>, <code>entries</code>.<code>authorId</code>, <code>entries</code>.<code>postDate</code>, <code>entries</code>.<code>expiryDate</code>
  FROM <code>craft_elements</code> <code>elements</code>
  JOIN <code>craft_elements_i18n</code> <code>elements_i18n</code> ON elements_i18n.elementId = elements.id
  JOIN <code>craft_content</code> <code>content</code> ON content.elementId = elements.id
  JOIN <code>craft_entries</code> <code>entries</code> ON entries.id = elements.id
  JOIN <code>craft_sections</code> <code>sections</code> ON sections.id = entries.sectionId
  LEFT JOIN <code>craft_structures</code> <code>structures</code> ON structures.id = sections.structureId
  LEFT JOIN <code>craft_structureelements</code> <code>structureelements</code> ON (structureelements.structureId = structures.id) AND (structureelements.elementId = entries.id)
  WHERE ((((elements_i18n.locale = :locale) AND (content.locale = :locale)) AND (elements.archived = 0)) AND (elements_i18n.enabled = 1)) AND (<code>sections</code>.<code>handle</code> IN ('policies'))
  GROUP BY <code>elements</code>.<code>id</code>
  ORDER BY <code>dateCreated</code>. Bound with :locale='en_us'</p>
</blockquote>

<p>Looks like you have <code>dateCreated</code> field in multiple tables used in the join and the statement is not explicitly defining the identity of the table ???</p>

<p>Can anyone help me to fix this?</p>

<templating><cache><craft2>
Failed Stale Template Cache Delete Error...Analyzed...But No Answer
# Failed Stale Template Cache Delete Error...Analyzed...But No Answer

(Asked by: username_0 on 2018-11-03)

For some of the extremely static content on my site, I use caching to prevent multiple db queries during every single load. I also have multiple locale on my site with custom cache key names. The actual execution of cache is running perfectly at the moment on all the locales. 
However, when I make changes to any entry which has cache enabled, I get stale template delete failed error. When I take look at the actual MySQL table, I see that the requisite cache row is deleted from the table upon making changes to an entry. So I don't quite understand why this error shows up.
Here is a typical cache directive I used in my templates
 {% cache globally using key  "www-features" for 24 hours %}

When I look at the runtime logs, I see following error which I am assuming it to be associated with this problem

2018/11/03 19:10:42 [error] [application] Encountered an error running task 17 (DeleteStaleTemplateCaches), step 13 of 29: An exception was thrown: 
  CDbCommand failed to execute the SQL statement: 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
  FROM craft_elements elements
  JOIN craft_elements_i18n elements_i18n ON elements_i18n.elementId = elements.id
  JOIN craft_content content ON content.elementId = elements.id
  JOIN craft_entries entries ON entries.id = elements.id
  JOIN craft_sections sections ON sections.id = entries.sectionId
  LEFT JOIN craft_structures structures ON structures.id = sections.structureId
  LEFT JOIN craft_structureelements structureelements ON (structureelements.structureId = structures.id) AND (structureelements.elementId = entries.id)
  WHERE ((((elements_i18n.locale = :locale) AND (content.locale = :locale)) AND (elements.archived = 0)) AND (elements_i18n.enabled = 1)) AND (sections.handle IN ('policies'))
  GROUP BY elements.id
  ORDER BY dateCreated. Bound with :locale='en_us'

Looks like you have dateCreated field in multiple tables used in the join and the statement is not explicitly defining the identity of the table ???
Can anyone help me to fix this?

**Tags:** templating, cache, craft2


---

## 1 answers

### Answer by username_0 on 2018-11-03. Score: 2

OK, I found the answer to this. Here is the [correct answer.](https://craftcms.stackexchange.com/questions/17458/failed-task-and-various-errors-in-logs)

Basically change `dateCreated` to `elements.dateCreated` in my template.


---

