-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4411 from artragis/fix_migrate
fix manage.py
- Loading branch information
Showing
1 changed file
with
23 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,35 @@ | ||
import os | ||
import sys | ||
|
||
|
||
def patch_create_suffix(original): | ||
""" | ||
Patch mysql creation policy to handle the "utf8mb4" facility. This appears tricky but it's necessary | ||
due to the conception of "extended utf-8" in mysql. If we do not patch, the mysql backend cannot index | ||
``VARCHAR(255)`` fields ! | ||
see <http://bd808.com/blog/2017/04/17/making-django-migrations-that-work-with-mysql-55-and-utf8mb4/> | ||
for explanations | ||
:param original: the original function we are patching | ||
:return: the patched function | ||
""" | ||
def patch(self): | ||
return original(self) + ' ROW_FORMAT=DYNAMIC' | ||
return patch | ||
|
||
|
||
if __name__ == '__main__': | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'zds.settings') | ||
|
||
from zds.settings import DATABASES | ||
if len(sys.argv) > 1 and sys.argv[1] in ['migrate', 'test']: | ||
|
||
if DATABASES['default']['ENGINE'] == 'django.db.backends.mysql': | ||
from django.db.backends.mysql.creation import BaseDatabaseCreation | ||
|
||
BaseDatabaseCreation.sql_table_creation_suffix = \ | ||
patch_create_suffix(BaseDatabaseCreation.sql_table_creation_suffix) | ||
from django.db.backends.mysql.schema import DatabaseSchemaEditor | ||
DatabaseSchemaEditor.sql_create_table += ' ROW_FORMAT=DYNAMIC' | ||
|
||
DatabaseSchemaEditor.sql_create_table += ' ROW_FORMAT=DYNAMIC' | ||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |