Steps to reproduce:
1) Upgrade from Roller 5.0 to Roller 5.1 via normal upgrade process
2) Login and edit one of your templates
3) Save your template and you'll get an error, if you look in the logs you will see that it is a Null Pointer Exception
This is caused because the Template does not have a "Template Code" object associated with it yet.
One possible way to fix this is: if a template code object is not found, then create a new one.