Issue after 8.5.x update towards 9.x - Foreign key constraint is incorrectly formed

Its a chicken and egg problem with dependencies in the oAuth tables (you can get similar with express), usually when updating the character set.

If the rest of the update works from the CLI, and you are not using oAuth, you can delete the tables and import them from a fresh 9.x install. Or @jero posted a script to fix from MySQL.