在Django中使用MySQL Connector和Python 3运行inpspectdb时出错

2024-04-25 21:34:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我将发布一个问题,然后发布问题的解决方案,我在被困了一段时间后找到了解决方案,因此我认为对于其他使用inspectdb命令的人来说,使用MySQL Connector for Python 3.3从MySQL数据库生成Django模型可能很有价值

命令:

C:\myproj\myproj> manage.py inspectdb --database=mydb > models.py

结果错误(为简洁起见,省略了回溯):

django.db.utils.IntegrityError: 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 ''decimal' at line 1

Tags: thetodjangopy模型命令数据库for
1条回答
网友
1楼 · 发布于 2024-04-25 21:34:08

所以解决方法非常快,请注意,信用卡归Marcin Miklaszewski所有,他在这里发布了bug和相关的解决方案:http://bugs.mysql.com/bug.php?id=72478 不过,我想在StackOverflow上找到它会更容易。你知道吗

文件的第65行有一个错误(假设在C:\Python33中安装了python):

C:\Python33\lib\site-packages\mysql\connector\django\introspection.py

更换管路65:

"table_schema = DATABASE() AND data_type='decimal", [table_name])"

使用:

"table_schema = DATABASE() AND data_type='decimal'", [table_name])"

(注意第一个版本中单词decimal后面缺少的撇号)。你知道吗

现在inspectdb命令将正确运行。你知道吗

相关问题 更多 >