[1.7.x] Fixed several flake8 errors

Backport of d17a4cb037 from master
[1.7.x] Added database migration for contrib.sites.

refs #22170.

Backport of ec6e2eac60 from master
[1.7.x] Added database migration for contrib.flatpages.

refs #22170.

Backport of 7da16b99df from master
[1.7.x] Added database migration for contrib.redirects.

refs #22170.

Backport of d7576bb27a from master