似乎无法使 Python、Peewee、pymysql 和 MySql 数据库正常工作,没有 'returning_clause' 错误

Can't seem to get Python, Peewee, pymysql & MySql database to work no 'returning_clause' error

我是 Python 的新手,正在尝试使用一个非常简单的 table 数据库。

我正在使用 python 3、peewee 和 pymysql。数据库是 MySQL,在我的 Windows 10 PC (wampserver) 上本地,代码是;

import pymysql
pymysql.install_as_MySQLdb()
import MySQLdb

import peewee
from peewee import *

db = MySQLdb.connect(user='xxxxx', passwd='xxxxx',
                     host='localhost', port=3306, db='xxxxx')


class SearchUrl(peewee.Model):
    id = peewee.AutoField()
    url = peewee.TextField()
    page_title = peewee.TextField()
    date_found = peewee.DateField()
    date_last_changed = peewee.DateField()
    article_status = peewee.CharField()
    description = peewee.TextField()

    class Meta:
        database = db


newUrl = SearchUrl.create(url='http://cropnosis.co.uk', page_title="Cropnosis Ltd.",
                          date_found='2018-04-13', status='new', description='Cropnosis website')

newUrl.save()

for url in SearchUrl.filter(url='http://cropnosis.co.uk'):
    print(url.description)

db.close()

每当我 运行 时,我都会在“SearchUrl.create”行中收到以下错误。我搜索了 'returning_clause' 属性,但发现很少或根本没有提及它,尤其是。关于 MySQL.

非常感谢任何帮助或相关链接。

Traceback (most recent call last):
  File "researcherDb.py", line 26, in <module>
    date_found='2018-04-13', status='new', description='Cropnosis website')
  File "C:\.dev\Client\Cropnosis\Researcher\lib\site-packages\peewee.py", line 5161, in create
    inst.save(force_insert=True)
  File "C:\.dev\Client\Cropnosis\Researcher\lib\site-packages\peewee.py", line 5284, in save
    pk_from_cursor = self.insert(**field_dict).execute()
  File "C:\.dev\Client\Cropnosis\Researcher\lib\site-packages\peewee.py", line 5128, in insert
    return ModelInsert(cls, cls._normalize_data(__data, insert))
  File "C:\.dev\Client\Cropnosis\Researcher\lib\site-packages\peewee.py", line 5868, in __init__
    if self.model._meta.database.returning_clause:
AttributeError: 'Connection' object has no attribute 'returning_clause'

你想要这个:

from peewee import *

# this is peewee.MySQLDatabase, not pymysql's connection class.
db = MySQLDatabase('the_db_name', user='xxxxx', passwd='xxxxx')