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

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

user2201
1#
user2201 Published in April 25, 2018, 8:22 am

I am pretty new to Python and trying to use a very simple one table DB.

I'm using python 3, peewee and pymysql. The database is MySQL, local on my Windows 10 PC (wampserver) and the code is;

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()

Whenever I run this I get the following error in the "SearchUrl.create" line. I have searched for the 'returning_clause' attribute but have found little or no mention of it esp. with regard to MySQL.

Any help or relevant links greatly appreciated.

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'
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.455018 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO