我对python非常陌生,尝试使用一个非常简单的单表db。
我正在使用python3、peewee和pymysql。数据库是mysql,在我的windows10pc(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\u 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'
1条答案
按热度按时间busg9geu1#
你想要这个: