django - Getting a SQL error when running "python manage.py migrate" using a MySQL database -


i've been through introductory tutorial django using sqlite per instructions. however, real project want use mysql, deleted tutorial project files , started fresh setup. trouble when run "python manage.py migrate" following mysql error:

_mysql_exceptions.programmingerror: (1064, "you have error in sql syntax; check manual corresponds mysql server version right syntax use near '%s' @ line 1").

i have following in site settings database section:

databases = {     'default': {         'engine': 'django.db.backends.mysql',         'name': 'vocabulator$database',         'user': 'vocabulator',         'password': '<password>',         'host': 'mysql.server',      } }  

i connected database in bash using, 'mysql --user=vocabulator --host=mysql.server --password=<password> "vocabulator\$database" ', appears have entered these setting details correctly.

i followed instruction on setting database bindings python 3, appeared work successfully. on either django documentation pages or pythonanywhere equivalent, unfortunately cannot locate page reference again.

i haven't written mysql queries myself yet, incorrect ones being made must coming manage.py, cause? complete error trace quoted below:

operations perform:   synchronize unmigrated apps: staticfiles, messages   apply migrations: contenttypes, sessions, admin, auth synchronizing apps without migrations:   creating tables...     running deferred sql...   installing custom sql... running migrations:   rendering model states... done   applying contenttypes.0001_initial...traceback (most recent call last):   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute     return self.cursor.execute(sql, params)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/db/backends/mysql/base.py", line 124, in execute     return self.cursor.execute(query, args)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/mysqldb/cursors.py", line 184, in execute     self.errorhandler(self, exc, value)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/mysqldb/connections.py", line 37, in defaulterrorhandler     raise errorvalue   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/mysqldb/cursors.py", line 171, in execute     r = self._query(query)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/mysqldb/cursors.py", line 330, in _query     rowcount = self._do_query(q)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/mysqldb/cursors.py", line 294, in _do_query     db.query(q) _mysql_exceptions.programmingerror: (1064, "you have error in sql syntax; check manual corresponds mysql server version right syntax use near '%s' @ line 1")  above exception direct cause of following exception:  traceback (most recent call last):   file "manage.py", line 10, in <module>     execute_from_command_line(sys.argv)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line     utility.execute()   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/core/management/__init__.py", line 330, in execute     self.fetch_command(subcommand).run_from_argv(self.argv)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/core/management/base.py", line 393, in run_from_argv     self.execute(*args, **cmd_options)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/core/management/base.py", line 444, in execute     output = self.handle(*args, **options)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 222, in handle     executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/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/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/db/migrations/executor.py", line 148, in apply_migration     state = migration.apply(state, schema_editor)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/db/migrations/migration.py", line 115, in apply     operation.database_forwards(self.app_label, schema_editor, old_state, project_state)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/db/migrations/operations/models.py", line 59, in database_forwards     schema_editor.create_model(model)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 289, in create_model     self.deferred_sql.extend(self._model_indexes_sql(model))   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/db/backends/mysql/schema.py", line 55, in _model_indexes_sql     self.connection.cursor(), model._meta.db_table   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/db/backends/mysql/introspection.py", line 142, in get_storage_engine     "where table_name = %s", [table_name])   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/db/backends/utils.py", line 79, in execute     return super(cursordebugwrapper, self).execute(sql, params)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute     return self.cursor.execute(sql, params)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/db/utils.py", line 97, in __exit__     six.reraise(dj_exc_type, dj_exc_value, traceback)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise     raise value.with_traceback(tb)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute     return self.cursor.execute(sql, params)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/django/db/backends/mysql/base.py", line 124, in execute     return self.cursor.execute(query, args)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/mysqldb/cursors.py", line 184, in execute     self.errorhandler(self, exc, value)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/mysqldb/connections.py", line 37, in defaulterrorhandler     raise errorvalue   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/mysqldb/cursors.py", line 171, in execute     r = self._query(query)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/mysqldb/cursors.py", line 330, in _query     rowcount = self._do_query(q)   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-packages/mysqldb/cursors.py", line 294, in _do_query     db.query(q) django.db.utils.programmingerror: (1064, "you have error in  sql syntax; check manual corresponds mysql server v ersion right syntax use near '%s' @ line 1") exception ignored in: <bound method cursor.__del__ of <mysqldb.curso rs.cursor object @ 0x7feec394b940>> traceback (most recent call last):   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-p ackages/mysqldb/cursors.py", line 67, in __del__   file "/home/vocabulator/.virtualenvs/django18/lib/python3.4/site-p ackages/mysqldb/cursors.py", line 73, in close referenceerror: weakly-referenced object no longer exists (django18)03:29 ~/mysite $ mysql --user=vocabulator --host=mysql.server --p mysql: ambiguous option '--p' (pager, plugin_dir) 

as said in comment above, found page had instructed me on how install drivers. one:

https://www.pythonanywhere.com/wiki/usingmysql

however, wiki page little dated , instructed me install mysql connector version 2.0.1. current version 2.0.4. old version had bug meant not operate django 1.8, stated here:

http://bugs.mysql.com/bug.php?id=76752

by version 2.0.4 bug appears have been corrected.

the line in pythonanywhere wiki page referenced above should change to:

pip3.4 install https://dev.mysql.com/get/downloads/connector-python/mysql-connector-python-2.0.4.tar.gz

once ran this, migration appears have worked on django installation.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -