虚拟机运行时mysql_在虚拟机中运行测试时Django MySQL错误

我有一个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相关的东西都在工作?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值