conversion between UTF8 and SQL_ASCII is not supported #5392

Closed
opened 2025-12-29 19:27:26 +01:00 by adam · 4 comments
Owner

Originally created by @bigbot123 on GitHub (Sep 20, 2021).

NetBox version

v3.0.1

Python version

3.9

Steps to Reproduce

  1. select Organization
  2. select Regions
  3. add a Regions which name is in Chinese or other language
  4. Pop-up this:
        <class 'django.db.utils.NotSupportedError'>
        
        conversion between UTF8 and SQL_ASCII is not supported
        LINE 1: ...a", "description": "", "custom_fields": {}}', '{"created": "...

Python version: 3.9.5
NetBox version: 3.0.1

Expected Behavior

a normal and successful write operation

Observed Behavior

Pop-up this:

        <class 'django.db.utils.NotSupportedError'>
        
        conversion between UTF8 and SQL_ASCII is not supported
        LINE 1: ...a", "description": "", "custom_fields": {}}', '{"created": "...
Originally created by @bigbot123 on GitHub (Sep 20, 2021). ### NetBox version v3.0.1 ### Python version 3.9 ### Steps to Reproduce 1. select Organization 2. select Regions 3. add a Regions which name is in Chinese or other language 4. Pop-up this: ``` <class 'django.db.utils.NotSupportedError'> conversion between UTF8 and SQL_ASCII is not supported LINE 1: ...a", "description": "", "custom_fields": {}}', '{"created": "... ``` Python version: 3.9.5 NetBox version: 3.0.1 ### Expected Behavior a normal and successful write operation ### Observed Behavior Pop-up this: ``` <class 'django.db.utils.NotSupportedError'> conversion between UTF8 and SQL_ASCII is not supported LINE 1: ...a", "description": "", "custom_fields": {}}', '{"created": "... ```
adam added the type: bugstatus: revisions needed labels 2025-12-29 19:27:26 +01:00
adam closed this issue 2025-12-29 19:27:26 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 20, 2021):

Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.

@jeremystretch commented on GitHub (Sep 20, 2021): Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.
Author
Owner

@jbakklund commented on GitHub (Sep 22, 2021):

I do recognize the observed behaviour, and it is not caused by a bug in NetBox. It happens if your database accidently have been specified to use the limited SQL_ASCII encoding instead of UTF-8. The default encoding for PostgreSQL is usually setup by your packaging system at the time of installation, and stored in the template1 database.

You can run the following script to convert your database from SQL_ASCII to UTF8 encoding:

# convert createdb's template to UTF8
echo "UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';" | psql -U postgres
echo "drop database template1;" | psql -U postgres
echo "create database template1 with template = template0 encoding = 'UTF8';" | psql -U postgres
echo "update pg_database set datacl='{=c/postgres,postgres=CTc/postgres}' where datname='template1';" | psql -U postgres
echo "UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';" | psql -U postgres

# export and reimport as UTF8
pg_dump -U postgres --encoding utf8 netbox -f netbox_utf8.sql
createdb -U postgres -E utf8 netbox_utf8
psql -U postgres -f netbox_utf8.sql -d netbox_utf8
echo "ALTER DATABASE netbox RENAME TO netbox_ascii" | psql -U postgres
echo "ALTER DATABASE netbox_utf8 RENAME TO netbox" | psql -U postgres 

The script above is based on a script posted by @adammeghji

The encoding and locale settings on the server must match those of the template database, unless template0 is used as a template while creating a database for NetBox from scratch.

My suggestion is to update the documentation by adding the following alternative for how to create a database for NetBox which is able to support most languages.

Database Creation

...
To create a database for NetBox with enhanced support for various languages, use the following command:

CREATE DATABASE netbox ENCODING 'UTF8' LC_COLLATE='C.UTF-8' LC_CTYPE='C.UTF-8' TEMPLATE template0;
@jbakklund commented on GitHub (Sep 22, 2021): I do recognize the observed behaviour, and it is not caused by a bug in NetBox. It happens if your database accidently have been specified to use the limited SQL_ASCII encoding instead of UTF-8. The default encoding for PostgreSQL is usually setup by your packaging system at the time of installation, and stored in the `template1` database. You can run the following script to convert your database from SQL_ASCII to UTF8 encoding: ``` # convert createdb's template to UTF8 echo "UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';" | psql -U postgres echo "drop database template1;" | psql -U postgres echo "create database template1 with template = template0 encoding = 'UTF8';" | psql -U postgres echo "update pg_database set datacl='{=c/postgres,postgres=CTc/postgres}' where datname='template1';" | psql -U postgres echo "UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';" | psql -U postgres # export and reimport as UTF8 pg_dump -U postgres --encoding utf8 netbox -f netbox_utf8.sql createdb -U postgres -E utf8 netbox_utf8 psql -U postgres -f netbox_utf8.sql -d netbox_utf8 echo "ALTER DATABASE netbox RENAME TO netbox_ascii" | psql -U postgres echo "ALTER DATABASE netbox_utf8 RENAME TO netbox" | psql -U postgres ``` The script above is based on a [script](https://gist.github.com/adammeghji/5637522) posted by @adammeghji The encoding and locale settings on the server must match those of the template database, unless `template0` is used as a template while creating a database for NetBox from scratch. My suggestion is to update the documentation by adding the following alternative for how to create a database for NetBox which is able to support most languages. ### Database Creation ... To create a database for NetBox with enhanced support for various languages, use the following command: ``` CREATE DATABASE netbox ENCODING 'UTF8' LC_COLLATE='C.UTF-8' LC_CTYPE='C.UTF-8' TEMPLATE template0; ```
Author
Owner

@DanSheps commented on GitHub (Sep 22, 2021):

This seems to be "Not a Bug". Going to close this out.

@DanSheps commented on GitHub (Sep 22, 2021): This seems to be "Not a Bug". Going to close this out.
Author
Owner

@bigbot123 commented on GitHub (Sep 23, 2021):

Thanks for your guide, it's my mistake,
You are so professional and erudite

  • v -

| |
bigbot123
|
|
@.***
|
签名由网易邮箱大师定制
On 9/23/2021 03:50,Daniel @.***> wrote:

This seems to be "Not a Bug". Going to close this out.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

@bigbot123 commented on GitHub (Sep 23, 2021): Thanks for your guide, it's my mistake, You are so professional and erudite - v - | | bigbot123 | | ***@***.*** | 签名由网易邮箱大师定制 On 9/23/2021 03:50,Daniel ***@***.***> wrote: This seems to be "Not a Bug". Going to close this out. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5392