Created
November 26, 2020 13:09
-
-
Save flyte/39517caad8358fc90b73e160e228b916 to your computer and use it in GitHub Desktop.
Change MySQL/MariaDB character set and collation to something sane
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import connection | |
DB_NAME = "your-db-name" | |
cursor = connection.cursor() | |
tables = connection.introspection.table_names() | |
cursor.execute(f"ALTER DATABASE `{DB_NAME}` CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci") | |
for table in tables: | |
cursor.execute(f"ALTER TABLE {table} CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment