We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Migrations that alter sensitive schema fail
I am using `mysql  Ver 14.14 Distrib 5.5.46, for debian-linux-gnu (x86_64) using readline 6.3`.

``` pytb
./manage.py migrate 
2016-01-22 09:33:09,204 INFO Using Python PO
Operations to perform:
  Synchronize unmigrated apps: django_rq, pootle_profile, staticfiles, pootle_terminology, debug_toolbar, pootle, allauth, humanize, contact, django_extensions, import_export, django_assets, pootle_misc, overextends
  Apply all migrations: account, pootle_store, pootle_language, virtualfolder, pootle_app, pootle_project, sites, auth, reports, contenttypes, pootle_translationproject, accounts, pootle_statistics, sessions, staticpages, socialaccount
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  Rendering model states... DONE
  Applying pootle_app.0005_case_sensitive_schema...Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    execute_from_command_line()
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 222, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 110, in migrate
    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 148, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 112, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/migrations/operations/special.py", line 183, in database_forwards
    self.code(from_state.apps, schema_editor)
  File "/home/leo/Escritorio/core_pootle/pootle/apps/pootle_app/migrations/0005_case_sensitive_schema.py", line 17, in make_directory_paths_cs
    "varchar(255)")
  File "/home/leo/Escritorio/core_pootle/pootle/core/utils/db.py", line 44, in set_mysql_collation_for_column
    column, schema, collation))
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/utils.py", line 98, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 124, in execute
    return self.cursor.execute(query, args)
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
django.db.utils.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-core-django-17.pootle_app_directory MODIFY pootle_path  varchar(255)  character' at line 1")
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pootle/core/utils/db.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) Pootle contributors.
4 #
5 # This file is a part of the Pootle project. It is distributed under the GPL3
6 # or later license. See the LICENSE file for a copy of the license and the
7 # AUTHORS file for copyright and authorship information.
8 
9 
10 def set_mysql_collation_for_column(apps, cursor, model, column, collation, schema):
11     """Set the collation for a mysql column if it is not set already
12     """
13 
14     # Check its mysql - should probs check its not too old.
15     if not hasattr(cursor.db, "mysql_version"):
16         return
17 
18     # Get the db_name
19     db_name = cursor.db.get_connection_params()['db']
20 
21     # Get table_name
22     table_name = apps.get_model(model)._meta.db_table
23 
24     # Get the current collation
25     cursor.execute(
26         "SELECT COLLATION_NAME"
27         " FROM information_schema.columns"
28         " WHERE TABLE_SCHEMA = '%s'"
29         "  AND TABLE_NAME = '%s'"
30         "  AND COLUMN_NAME = '%s';"
31         % (db_name, table_name, column))
32     current_collation = cursor.fetchone()[0]
33 
34     if current_collation != collation:
35         # set collation
36         cursor.execute(
37             "ALTER TABLE %s.%s"
38             " MODIFY %s"
39             "  %s"
40             "  character set utf8"
41             "  collate %s"
42             "  NOT NULL;"
43             % (db_name, table_name,
44                column, schema, collation))
45
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pootle/core/utils/db.py b/pootle/core/utils/db.py
--- a/pootle/core/utils/db.py
+++ b/pootle/core/utils/db.py
@@ -24,7 +24,7 @@
     # Get the current collation
     cursor.execute(
         "SELECT COLLATION_NAME"
-        " FROM information_schema.columns"
+        " FROM `information_schema`.`columns`"
         " WHERE TABLE_SCHEMA = '%s'"
         "  AND TABLE_NAME = '%s'"
         "  AND COLUMN_NAME = '%s';"
@@ -34,11 +34,11 @@
     if current_collation != collation:
         # set collation
         cursor.execute(
-            "ALTER TABLE %s.%s"
-            " MODIFY %s"
+            "ALTER TABLE `%s`.`%s`"
+            " MODIFY `%s`"
             "  %s"
-            "  character set utf8"
-            "  collate %s"
+            "  CHARACTER SET utf8"
+            "  COLLATE %s"
             "  NOT NULL;"
             % (db_name, table_name,
                column, schema, collation))

{"golden_diff": "diff --git a/pootle/core/utils/db.py b/pootle/core/utils/db.py\n--- a/pootle/core/utils/db.py\n+++ b/pootle/core/utils/db.py\n@@ -24,7 +24,7 @@\n     # Get the current collation\n     cursor.execute(\n         \"SELECT COLLATION_NAME\"\n-        \" FROM information_schema.columns\"\n+        \" FROM `information_schema`.`columns`\"\n         \" WHERE TABLE_SCHEMA = '%s'\"\n         \"  AND TABLE_NAME = '%s'\"\n         \"  AND COLUMN_NAME = '%s';\"\n@@ -34,11 +34,11 @@\n     if current_collation != collation:\n         # set collation\n         cursor.execute(\n-            \"ALTER TABLE %s.%s\"\n-            \" MODIFY %s\"\n+            \"ALTER TABLE `%s`.`%s`\"\n+            \" MODIFY `%s`\"\n             \"  %s\"\n-            \"  character set utf8\"\n-            \"  collate %s\"\n+            \"  CHARACTER SET utf8\"\n+            \"  COLLATE %s\"\n             \"  NOT NULL;\"\n             % (db_name, table_name,\n                column, schema, collation))\n", "issue": "Migrations that alter sensitive schema fail\nI am using `mysql  Ver 14.14 Distrib 5.5.46, for debian-linux-gnu (x86_64) using readline 6.3`.\n\n``` pytb\n./manage.py migrate \n2016-01-22 09:33:09,204 INFO Using Python PO\nOperations to perform:\n  Synchronize unmigrated apps: django_rq, pootle_profile, staticfiles, pootle_terminology, debug_toolbar, pootle, allauth, humanize, contact, django_extensions, import_export, django_assets, pootle_misc, overextends\n  Apply all migrations: account, pootle_store, pootle_language, virtualfolder, pootle_app, pootle_project, sites, auth, reports, contenttypes, pootle_translationproject, accounts, pootle_statistics, sessions, staticpages, socialaccount\nSynchronizing apps without migrations:\n  Creating tables...\n    Running deferred SQL...\n  Installing custom SQL...\nRunning migrations:\n  Rendering model states... DONE\n  Applying pootle_app.0005_case_sensitive_schema...Traceback (most recent call last):\n  File \"./manage.py\", line 22, in <module>\n    execute_from_command_line()\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/core/management/__init__.py\", line 354, in execute_from_command_line\n    utility.execute()\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/core/management/__init__.py\", line 346, in execute\n    self.fetch_command(subcommand).run_from_argv(self.argv)\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/core/management/base.py\", line 394, in run_from_argv\n    self.execute(*args, **cmd_options)\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/core/management/base.py\", line 445, in execute\n    output = self.handle(*args, **options)\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py\", line 222, in handle\n    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/migrations/executor.py\", line 110, in migrate\n    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/migrations/executor.py\", line 148, in apply_migration\n    state = migration.apply(state, schema_editor)\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/migrations/migration.py\", line 112, in apply\n    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/migrations/operations/special.py\", line 183, in database_forwards\n    self.code(from_state.apps, schema_editor)\n  File \"/home/leo/Escritorio/core_pootle/pootle/apps/pootle_app/migrations/0005_case_sensitive_schema.py\", line 17, in make_directory_paths_cs\n    \"varchar(255)\")\n  File \"/home/leo/Escritorio/core_pootle/pootle/core/utils/db.py\", line 44, in set_mysql_collation_for_column\n    column, schema, collation))\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/backends/utils.py\", line 79, in execute\n    return super(CursorDebugWrapper, self).execute(sql, params)\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/backends/utils.py\", line 64, in execute\n    return self.cursor.execute(sql, params)\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/utils.py\", line 98, in __exit__\n    six.reraise(dj_exc_type, dj_exc_value, traceback)\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/backends/utils.py\", line 62, in execute\n    return self.cursor.execute(sql)\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py\", line 124, in execute\n    return self.cursor.execute(query, args)\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/MySQLdb/cursors.py\", line 205, in execute\n    self.errorhandler(self, exc, value)\n  File \"/home/leo/.virtualenvs/coreptl/local/lib/python2.7/site-packages/MySQLdb/connections.py\", line 36, in defaulterrorhandler\n    raise errorclass, errorvalue\ndjango.db.utils.ProgrammingError: (1064, \"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-core-django-17.pootle_app_directory MODIFY pootle_path  varchar(255)  character' at line 1\")\n```\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\n\ndef set_mysql_collation_for_column(apps, cursor, model, column, collation, schema):\n    \"\"\"Set the collation for a mysql column if it is not set already\n    \"\"\"\n\n    # Check its mysql - should probs check its not too old.\n    if not hasattr(cursor.db, \"mysql_version\"):\n        return\n\n    # Get the db_name\n    db_name = cursor.db.get_connection_params()['db']\n\n    # Get table_name\n    table_name = apps.get_model(model)._meta.db_table\n\n    # Get the current collation\n    cursor.execute(\n        \"SELECT COLLATION_NAME\"\n        \" FROM information_schema.columns\"\n        \" WHERE TABLE_SCHEMA = '%s'\"\n        \"  AND TABLE_NAME = '%s'\"\n        \"  AND COLUMN_NAME = '%s';\"\n        % (db_name, table_name, column))\n    current_collation = cursor.fetchone()[0]\n\n    if current_collation != collation:\n        # set collation\n        cursor.execute(\n            \"ALTER TABLE %s.%s\"\n            \" MODIFY %s\"\n            \"  %s\"\n            \"  character set utf8\"\n            \"  collate %s\"\n            \"  NOT NULL;\"\n            % (db_name, table_name,\n               column, schema, collation))\n", "path": "pootle/core/utils/db.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\n\ndef set_mysql_collation_for_column(apps, cursor, model, column, collation, schema):\n    \"\"\"Set the collation for a mysql column if it is not set already\n    \"\"\"\n\n    # Check its mysql - should probs check its not too old.\n    if not hasattr(cursor.db, \"mysql_version\"):\n        return\n\n    # Get the db_name\n    db_name = cursor.db.get_connection_params()['db']\n\n    # Get table_name\n    table_name = apps.get_model(model)._meta.db_table\n\n    # Get the current collation\n    cursor.execute(\n        \"SELECT COLLATION_NAME\"\n        \" FROM `information_schema`.`columns`\"\n        \" WHERE TABLE_SCHEMA = '%s'\"\n        \"  AND TABLE_NAME = '%s'\"\n        \"  AND COLUMN_NAME = '%s';\"\n        % (db_name, table_name, column))\n    current_collation = cursor.fetchone()[0]\n\n    if current_collation != collation:\n        # set collation\n        cursor.execute(\n            \"ALTER TABLE `%s`.`%s`\"\n            \" MODIFY `%s`\"\n            \"  %s\"\n            \"  CHARACTER SET utf8\"\n            \"  COLLATE %s\"\n            \"  NOT NULL;\"\n            % (db_name, table_name,\n               column, schema, collation))\n", "path": "pootle/core/utils/db.py"}]}