Minor bugfixes in the support to different encodings

Please cherry pick this pull request and ignore the changes in the compiler.py. The other changes are all related to minor bugfixes in the support to different encodings.

The main change is to always use the encoding defined in the settings (default: utf-8). Before this fix we had some problems writing unicode strings with special characters to the database and also in the introspection when the fields contains special characters.