![](/img/trans.png)
[英]"django.db.utils.ProgrammingError: relation "app_user" does not exist" during manage.py test
[英]python manage.py migrate returns with django.db.utils.ProgrammingError: (1064... error
我是一个新手,我正在尝试使用mysql
数据库在Windows 8
使用Python 3
和Django 1.8.6
创建一个 django 项目
当我执行python manage.py migrate
我得到一个错误
django.db.utils.ProgrammingError: (1064 ....
我已经交叉检查了我的 settings.py 文件和所有内容。 事实上,连接已建立,有时它会成功创建表django_content_type
和django_migrations
,然后出现此错误,有时没有创建这些表本身,我会收到此错误。
打印的堆栈跟踪结束如下:
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 '%s' at line 1")
我还提到并尝试按照本站点其他类似查询中的说明(已安装 mysql-connector-python-2.1.3)进行操作,但似乎没有任何效果
完整的堆栈跟踪如下:
D:\pythonLearn\learningDjango\mysite>python manage.py migrate
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 64, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 124, in execute return self.cursor.execute(query, args)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 207, in execute self.errorhandler(self, exc, value)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\connections.py", line 37, in defaulterrorhandler raise errorvalue
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 192, in execute r = self._query(query)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 356, in _query rowcount = self._do_query(q)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 320, in _do_query db.query(q)
_mysql_exceptions.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 '%s' at line 1")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 354, in execute_from_command_line utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 346, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 394, in run_from_argv self.execute(*args, **cmd_options)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 445, in execute output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\commands\migrate.py", line 93, in handle executor = MigrationExecutor(connection, self.migration_progress_callback)
File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 19, in __init__self.loader = MigrationLoader(self.connection)
File "C:\Python34\lib\site-packages\django\db\migrations\loader.py", line 47, in __init__self.build_graph()
File "C:\Python34\lib\site-packages\django\db\migrations\loader.py", line 188, in build_graph self.applied_migrations = recorder.applied_migrations()
File "C:\Python34\lib\site-packages\django\db\migrations\recorder.py", line 59, in applied_migrations self.ensure_schema()
File "C:\Python34\lib\site-packages\django\db\migrations\recorder.py", line 53, in ensure_schema editor.create_model(self.Migration)
File "C:\Python34\lib\site-packages\django\db\backends\base\schema.py", line 289, in create_model self.deferred_sql.extend(self._model_indexes_sql(model))
File "C:\Python34\lib\site-packages\django\db\backends\mysql\schema.py", line 56, in _model_indexes_sql self.connection.cursor(), model._meta.db_table
File "C:\Python34\lib\site-packages\django\db\backends\mysql\introspection.py", line 142, in get_storage_engine
"WHERE table_name = %s", [table_name])
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 79, in execute return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 64, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\utils.py", line 98, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python34\lib\site-packages\django\utils\six.py", line 658, in reraise raise value.with_traceback(tb)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 64, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 124, in execute return self.cursor.execute(query, args)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 207, in execute self.errorhandler(self, exc, value)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\connections.py", line 37, in defaulterrorhandler raise errorvalue
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 192, in execute r = self._query(query)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 356, in _query rowcount = self._do_query(q)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 320, in _do_query db.query(q)
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 '%s' at line 1")
django.db.utils.ProgrammingError: (1064, “您的 SQL 语法有错误;请检查与您的 MySQL 服务器版本相对应的手册,以获取在第 1 行附近的 '(6) NOT NULL)' 附近使用的正确语法” )
需要将mysql升级到5.6或更高版本。 这是由于 DATETIME(6) 引起的。 支持 5.6 或 lated 版本。
您的错误消息说...
...要在第 1 行的“%s”附近使用正确的语法
这意味着您的程序传递给 MySQL 的查询包含文本字符串%s
。 在我看来,您的程序没有将值替换到该字符串中。 它必须在尝试使用字符串作为查询之前这样做。
这种在查询中使用占位符的业务很常见。 你的查询有可能是这样的吗?
INSERT INTO names (name) VALUES (%s)
它需要这样说
INSERT INTO names (name) VALUES ('Ban Ki Moon')
正如@krishna chandak 所说,由于DATETIME(6)
,您应该升级MySQL
版本。
yum update yum
yum install yum-utils
mysqldump --lock-all-tables --all-databases -uroot -yourpassword >/root/all_dbs.sql
service mysqld stop
wget https://dev.mysql.com/get/mysql80-community-release-el6-2.noarch.rpm
sudo rpm -Uvh mysql80-community-release-el6-2.noarch.rpm
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
sudo yum-config-manager --enable mysql57-community
sudo yum-config-manager --disable mysql80-community
yum remove mysql55-server
yum install mysql57-server
yum update mysql
service mysqld start
mysql_upgrade -uroot -p
通过添加更改配置/etc/my.cnf
datadir=/var/lib/mysql
并评论这个字符串
# socket=/var/lib/mysql/mysql.sock
然后执行更新数据库的步骤并将配置返回到以前的状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.