rake aborted!
ActiveRecord::StatementInvalid: PG::InvalidParameterValue: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
HINT: Use the same encoding as in the template database, or use template0 as template.
: CREATE DATABASE "praveen" ENCODING = 'unicode'
I manually created the database using 'template tepmplate0' but rake is again trying to create the database. I tried rake db:migrate db:schema:load but it still failing to create database.
I had to manually change encoding of template1 to UTF8 for this to work.
postgres=# update pg_database set datistemplate='false' where datname='template1';
UPDATE 1
postgres=# drop database template1;
DROP DATABASE
postgres=# create database template1 encoding='UTF8' template template0;
CREATE DATABASE
postgres=# update pg_database set datistemplate='true' where datname='template1';
UPDATE 1
Rather than alter your templates, I think you can just specify which template to use in database.yml config:
postgres: &postgres
template: template0
Changing the encoding of the template databases to UTF-8 is a common and I'd say expected thing to do on a PostgreSQL setup, it's part of the setup. If you don't want to alter the template you can still specify the encoding while database creation manually.
Always trouble with Postgres. It is probably the best SQL database but at the same time the most user unfriendly one. I had to add a line for UTF-8 as well:
default: &default
encoding: utf8
template: template0
Most helpful comment
Rather than alter your templates, I think you can just specify which template to use in database.yml config: