Database create table then insert gives 'Invalid table' error

This is not the right way to check if a table exists. I’m not sure what Db::select() returns when the table doesn’t exist, but I don’t think it throws an exception, so setting $district_table_exists = false; in the catch clause is a problem.

So check what $selectResult actually returns and act on that. Or check out $database->validateTable() | Kirby CMS.