This issue is related to MDL-25789.
tag_insance.tiuserid is defined as not null, so a default value should be defined too. It broke moodle 2 upgrade.
Upgrade fails when adding fields to tag_instance table.
Fix old upgrade code that is causing discrepancies between fresh installs and upgraded sites.
As commented in the pull request, closing this as duplicate of MDL-26071. Please try to fix (needed steps given there) and tell SamH to integrate it.