'MySQL OperationalError when deleting from DataJoint table after restricting with its part table: "You can't specify target table : 'part_table'"

Using DataJoint Python (0.12.9) on Ubuntu with MySQL 5.7 .

Am running into an error with what I believed to be a fairly standard operation.

Have a table named Table with a part Table.Part.

Restricting Table as such:


Table & Table.Part

gives me the entries in Table common to Table.Part. However, wrapping this in a delete statement (either delete or delete_quick) as such:

(Table & Table.Part).delete()

gives me the following error:

OperationalError: (1093, "You can't specify target table '#table__part' for update in FROM clause")

Do not understand why "target table" is '#table__part' here, when I am attempting to delete from '#table'.



Solution 1:[1]

Perhaps this would work

(Table & (Table & Table.Part).fetch('KEY')).delete()

"target table" is "#table__part" is likely because you are also deleting entries from the Table.Part table as well (cascade delete)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thinh Nguyen