<p>Solved this one by adding SET foreign_key_checks = 0; to the beginning of the SQL dump and SET foreign_key_checks = 1; at the end of the file. Not sure if it is the best solution but it certainly worked.</p>

CC BY-SA 3.0
2016-06-08T20:18:00.563Z
This is just kicking the can down the road.  You've got inconsistent data in your database (for whatever reason) that should be fixed.  Settings FK checks to 0 on import is just saying "ignore those problems".
Brad Bell
CC BY-SA 3.0
2016-06-09T08:57:03.353Z
@bradbell yes I realise this. Can you suggest anyway of fixing the inconsistent data? What we need to check for and any preferred software to do it? Cheers.
Lettie
CC BY-SA 3.0
2016-06-09T16:51:19.860Z
For this particular error, it's complaining about data that's in the `elementId` column of the `craft_matrixcontent_newscontent` table that is missing in the `id` column of the `craft_elements` table.  So you'd want to write a SQL query that finds the missing data. https://stackoverflow.com/questions/3826929/sql-query-to-find-missing-rows-between-two-related-tables
Brad Bell
CC BY-SA 3.0
2016-06-13T08:59:15.683Z
Cheers @bradbell will create something.
Lettie
CC BY-SA 3.0
2016-06-08T16:00:40.267Z
2016-06-08T16:00:40.267Z
Lettie
<p>Since upgrading to craft 2.6.2785 when I delete a user it appears to remove the user from the <code>elements</code> and <code>elements_il8n</code> tables but does not delete the user from the <code>users</code> table.</p>

<p>If you then search for the user in the CMS it does not find them however the user has not been removed from the database so if you try and set up a new user with the same email address it fails with "email has already been taken message".</p>

<hr>

<p>Update on this. I re-imported the database from dev to staging. In my dev deleting users works fine. When importing the database which is fairly large due to 20k+ users I get this error:</p>

<pre><code>SQL Error (1452) Cannot add or update a child row:a foreign key constraint fails ('databaseName'.'#sql-1510_62265', CONSTRAINT 'craft_matrixcontent_newscontent_elementId_fk' FOREIGN KEY ('elementId') REFERENCES 'craft_elements' ('id') ON DELETE CASCADE)
</code></pre>

<p>Then when trying to delete a user it says it's deleted removes the elements from the element tables but does not remove the user from the <code>users</code> table.</p>

CC BY-SA 3.0
2016-06-08T10:46:54.540Z
Were any Entries authored by the deleted user?
Matt P
CC BY-SA 3.0
2016-06-08T12:34:32.440Z
No no entries. I think this maybe to do with a possible corrupt database or plugin now so will investigate further.
Lettie
<users><database><mysql><delete>
Users not being deleted from the craft_users table?
# Users not being deleted from the craft_users table?

(Asked by: username_0 on 2016-06-08)

Since upgrading to craft 2.6.2785 when I delete a user it appears to remove the user from the elements and elements_il8n tables but does not delete the user from the users table.
If you then search for the user in the CMS it does not find them however the user has not been removed from the database so if you try and set up a new user with the same email address it fails with "email has already been taken message".

Update on this. I re-imported the database from dev to staging. In my dev deleting users works fine. When importing the database which is fairly large due to 20k+ users I get this error:
SQL Error (1452) Cannot add or update a child row:a foreign key constraint fails ('databaseName'.'#sql-1510_62265', CONSTRAINT 'craft_matrixcontent_newscontent_elementId_fk' FOREIGN KEY ('elementId') REFERENCES 'craft_elements' ('id') ON DELETE CASCADE)

Then when trying to delete a user it says it's deleted removes the elements from the element tables but does not remove the user from the users table.

**Tags:** users, database, mysql, delete

> **Comments:**
> **username_1**: Were any Entries authored by the deleted user?  
> **username_0**: No no entries. I think this maybe to do with a possible corrupt database or plugin now so will investigate further.  

---

## 1 answers

### Answer by username_0 on 2016-06-08. Score: 1

Solved this one by adding SET foreign\_key\_checks = 0; to the beginning of the SQL dump and SET foreign\_key\_checks = 1; at the end of the file. Not sure if it is the best solution but it certainly worked.

> **Comments:**
> **username_2**: This is just kicking the can down the road.  You've got inconsistent data in your database (for whatever reason) that should be fixed.  Settings FK checks to 0 on import is just saying "ignore those problems".  
> **username_0**: @bradbell yes I realise this. Can you suggest anyway of fixing the inconsistent data? What we need to check for and any preferred software to do it? Cheers.  
> **username_2**: For this particular error, it's complaining about data that's in the `elementId` column of the `craft_matrixcontent_newscontent` table that is missing in the `id` column of the `craft_elements` table.  So you'd want to write a SQL query that finds the missing data. https://stackoverflow.com/questions/3826929/sql-query-to-find-missing-rows-between-two-related-tables  
> **username_0**: Cheers @bradbell will create something.  

---

