我有一个Django应用程序在我的本地python3.6版本上运行得很好,我想确保它在其他地方安装时也能做到。在
为此,我创建了一个virtualenv,使用的Python版本在全局范围内运行良好,但没有任何包:virtualenv --no-site-packages --python=$(which python3.6) clear_env
source clear_env/bin/activate
然后我在本地安装了这些需求:
^{2}$
当我尝试运行服务器时,甚至当我使用管理面板并对数据库进行更改时,一切都正常。
但是,当我运行测试时:python manage.py test --nomigrations
我得到以下错误: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 '(6) NOT NULL, `user_id` integer NOT NULL, `content_type_id` integer NULL, `objec' at line 1")
追溯到:File "/home/niki/basic-django-ecommerce-site/clear_env/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
File "/home/niki/basic-django-ecommerce-site/clear_env/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/home/niki/basic-django-ecommerce-site/clear_env/lib/python3.6/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/home/niki/basic-django-ecommerce-site/clear_env/lib/python3.6/site-packages/MySQLdb/cursors.py", line 312, in _query
db.query(q)
File "/home/niki/basic-django-ecommerce-site/clear_env/lib/python3.6/site-packages/MySQLdb/connections.py", line 224, in query
_mysql.connection.query(self, query)
MySQLdb._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 '(6) NOT NULL, `user_id` integer NOT NULL, `content_type_id` integer NULL, `objec' at line 1")
注意:我在测试中使用--nomigrations标志来避免{a1}。这在我的global Python环境中同样非常有效。在
最初我认为这个问题可能与一些缺失的linux MySQL/Python包有关,similar to that issue。我记得有一次我必须安装类似libmysqlclient-dev python-dev的东西,然后重新编译Python版本才能使其正常工作。在
但是,如果我的virutalenv使用的Python版本是全局工作的,那么原因是什么呢?更奇怪的是,为什么只有测试失败并出现错误,runserver和其他与DB相关的东西都在工作?在