﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27061	Support creating the TEST PostgreSQL database from a custom template	Chris Jerdonek	Chris Jerdonek	"Using PostgreSQL 9.3.13, when I set the `TEST` database setting `CHARSET` to `UTF8` and run tests with a personal project, I get the following error:

> Got an error creating the test database: 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.

I believe the way to do this in postgres is something like:

{{{#!sql
CREATE DATABASE <name> WITH TEMPLATE template0 ENCODING 'UTF8'
}}}

(See [https://www.postgresql.org/docs/current/static/sql-createdatabase.html here] for postgres documentation.)

You can see [https://github.com/django/django/blob/d7e0cf04b77c859d895e81ddb7af06a2ccfda5a7/django/db/backends/postgresql/creation.py#L8 here] in Django's `sql_table_creation_suffix()` that it doesn't allow passing a template name:

{{{#!python
def sql_table_creation_suffix(self):
    test_settings = self.connection.settings_dict['TEST']
    assert test_settings['COLLATION'] is None, (
        ""PostgreSQL does not support collation setting at database creation time.""
    )
    if test_settings['CHARSET']:
        return ""WITH ENCODING '%s'"" % test_settings['CHARSET']
    return ''
}}}

Perhaps adding a postgres-specific `TEMPLATE` setting to the `TEST` database settings would be a general way to solve this?
"	New feature	closed	Testing framework	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
