Avoid error when deleting database which does not exist
Fix order of tables creation to avoid foreign key errors

The creation of foreign keys fails when the target table
does not exist. The target tables must thus be created
before the referencing tables.