2

背景:

我正在尝试使用 Django 和现有的 MySQL 数据库构建一个支持多对多关系的数据库,作为完成 Django“民意调查”教程的下一步。

我正在运行一个包含 Python 3.4、Django 1.9.2、mysql-connector-python 2.1.3 的虚拟环境。

我正在通过项目 settings.py 中的 'ENGINE': 'mysql.connector.django' 连接到在 MAMP 上运行的 MySQL 数据库

我的项目中的设置应该是正确的,因为我使用 inspect db 从现有的 MySQL 数据库中提取模型没有问题。

问题:

查看并编辑创建的模型 inspectdb 后,我想将它们迁移到数据库。我将模型复制到应用程序的 models.py 并运行 migrate 命令。不幸的是,它现在抛出错误,并且是 django 的新手,我不太确定问题出在哪里。我正在看:

(开始错误摘录)

Operations to perform:
  Apply all migrations: admin, sessions, auth, contenttypes
Running migrations:
  Rendering model states... DONE
  Applying contenttypes.0001_initial...Traceback (most recent call last):
  File "/path/to/virtualenv/lib/python3.4/site-packages/mysql/connector/django/base.py", line 177, in _execute_wrapper
    return method(query, args)
  File "/path/to/virtualenv/lib/python3.4/site-packages/mysql/connector/cursor.py", line 515, in execute
    self._handle_result(self._connection.cmd_query(stmt))
  File "/path/to/virtualenv/lib/python3.4/site-packages/mysql/connector/cursor.py", line 434, in _handle_result
    self._handle_noresultset(result)
  File "/path/to/virtualenv/lib/python3.4/site-packages/mysql/connector/cursor.py", line 404, in _handle_noresultset
    self._warnings[0][1], self._warnings[0][2])
mysql.connector.errors.DatabaseError: 1264: Out of range value for column 'applied' at row 1

During handling of the above exception, another exception occurred:

(结束错误摘录)

我认为正在发生的事情

阅读该错误消息,我将两件事之一视为罪魁祸首:内容类型或 mysql 连接器设置('ENGINE':'mysql.connector.django')。

我找到了 ContentTypes 模型的 django 文档,但页面上的内容似乎无助于诊断我的问题。

我很好奇它是否是连接器,如果是这样,为什么 inspectdb 提取模型没有问题。

谁能给我一些关于发生了什么的见解?

谢谢!

4

1 回答 1

0

ATM 'mysql.connector.django' 似乎支持 Django 版本 <= 1.8

即使设置USE_TZ = True也会导致奇怪的 TypeErrors,例如:

“TypeError:不能将序列乘以‘元组’类型的非整数”

使用MySQLdbmysqlclient(这是一个 MySQLdb 分支)应该可以解决问题。

于 2016-10-12T02:36:12.760 回答