If you attempt to access a column in a non-existent row, you get anvil.tables.TableError.
So to perform a cascading delete, you can iterate over the linking table and handle that exception:
@anvil.server.callable
def cascade_the_delete():
for table2_row in app_tables.table2.search():
try:
# Try to access the linked row
table2_row['table1_row']['some_column']
except anvil.tables.TableError:
# The linked row doesn't exist, so delete the linking row
table2_row.delete()
# Alternatively, could set table2_row['table1_row'] = None to
# remove the dangling link rather than deleting the row
As I’ve said in that final comment, if you wanted to tidy up the dangling links rather than deleting the entire row, you could replace table2_row.delete() with table2_row['table1_row1'] = None.
It goes without saying, but … I recommend testing anything that deletes data in a dummy app before implementing in the production app!