rake db:create encoding error with postgresql rake db:create encoding error with postgresql postgresql postgresql

rake db:create encoding error with postgresql


To fix this in Rails, I've found that you can simply add the following line to each section (development/production etc.) of your database.yml file:

template: template0

See ActiveRecord/ConnectionAdapters/PostgreSQL/SchemaStatements#create_database for other options.


The main problem here is that your template database (template1) has been created with an ASCII encoding and you're telling PostgreSQL to create the new database with UTF8 encoding. Needless to say, it's not particularly pleased about that. What you can do is erase your template1 database and re-create it using these instructions. This can also be a problem when your hosting provider hasn't properly set the locale. You can read more about fixing your missing locales.

I found all of this info through this post about Fixing PostgreSQL's default encoding on Ubuntu 9.10


You can change postgres template1 to be UTF by doing the following as posted here:

UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';DROP DATABASE template1;CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';\c template1VACUUM FREEZE;UPDATE pg_database SET datallowconn = FALSE WHERE datname = 'template1';