FAQ Database Discussion Community


WTForm does not entirely repopulate form data upon editing a model

python,flask,wtforms,peewee
Edit: Category field is now able to repopulate. Made a mistake in retrieving the data. App.py has been edited. I recently created an "edit post" form in which the user clicks on a link, and a few parameters are sent to a function. My function searches for the post...

peewee, mysql and auto incrementing id

python,mysql,peewee
I have model in peewee ORM with unique=True field. Im saving data to my MySQL db like this : try: model.save() except IntegrityError: # do not save if it's already in db pass But when peewee trying to save data that already in db, MySQL increments id and ids order...

Does anyone have an example to store crawl data from scrapy to MySQLdb using Peewee?

python,mysql,scrapy,mysql-python,peewee
I'm new to Scrapy. I have Googled around and searched in Stack Overflow, but there's no exact things I want to do. I have been struggling with these for two days. This is what I have gotten so far for pipelines.py. Would anyone point out what's wrong with it or...

Peewee: reducing where conditionals break after a certain length

python,peewee
This is what I have: SomeTable.select.where(reduce(operator.or_, (SomeTable.stuff == entry for entry in big_list))) The problem arises when I have a relatively large list of elements in big_list and I get this: RuntimeError: maximum recursion depth exceeded Is there another way to approach this that doesn't involve splitting up the list...

concatenate strings with atomic update in peewee using sqlite db

sqlite,peewee
I would like to update a text field in an sqlite database created using the peewee python library. Specifically I would like to use peewee's atomic updates something like: query = Table.update(textfield = Table.textfield + 'string').where(some condition) query.execute() This type of update works fine for numeric fields but not for...

order_by() method not working in peewee

orm,peewee
I am using a SQLite backend with a simple show - season - episode schema: class Show(BaseModel): name = CharField() class Season(BaseModel): show = ForeignKeyField(Show, related_name='seasons') season_number = IntegerField() class Episode(BaseModel): season = ForeignKeyField(Season, related_name='episodes') episode_number = IntegerField() and I would need the following query : seasons = (Season.select(Season, Episode)...

Change the column order in a table for a subclassed model

python,sqlite,peewee
In a situation where you have a subclassed model in peewee, how do you tell peewee what order to create the columns in the table? In the following example, the order is "b, c, a", but I want "a, b, c". class BaseModel(Model): b = CharField() c = CharField() class...

How to ordering SQL result in Union peewee orm

python,mysql,python-2.7,peewee
I use peewee ORM for connecting to MySQL server. I wrote this code: c = ( Comments().select( Comments, Member.id.alias('member_id'), Member.username, Member.name, Member.family, Member.image_name ).join( Users, on=(Comments.user_key == Users.user_key) ).join( Member, on=(Member.username == Users.username).alias('member') ).where( Comments.element_key == element_key, Comments.status << [ Comments().EnumStatus.ACCEPT, Comments().EnumStatus.REPORT ] ) | Comments().select( Comments, Admin_users.id.alias('member_id'), Admin_users.username,...

KeyError: 'security' in Flask_security?

python,flask,peewee,flask-security
I'm building a website using Flask in which I'm now trying to use Flask_Security for token based authentication. I now want to get an auth_token from the user, for which I use the get_auth_token() method. Unfortunately I get the stacktrace below this message. Does anybody know what's wrong? All tips...

How to do select with where on second order ForeignKeyField in Python Peewee ORM?

python,database,select,orm,peewee
I'm using the (awesome) Peewee ORM for my database needs and I now constructed a query as follows: OauthCI.select().where(OauthCI.oauth.user.id == 2) So OauthCI has a ForeignKeyField called oauth, which points to a table which in turn has a ForeignKeyField which is called user. Unfortunately, this gives me an error saying:...

Peewee KeyError: 'i'

python,flask,peewee
I am getting an odd error from Python's peewee module that I am not able to resolve, any ideas? I basically want to have 'batches' that contain multiple companies within them. I am making a batch instance for each batch and assigning all of the companies within it to that...

peewee.IntegrityError: NOT NULL constraint failed

python,flask,peewee
I'm trying to create a relational database but when the constructor is called I get the following error peewee.IntegrityError: NOT NULL constraint failed language.content_id. I have tried on many different ways to get this done but there is a problem when calling models.Language.create(). The other calls to insert into the...

Delete an element from peewee Query select

python,select,delete,peewee
I have a Query result by Peewee's table.select(), lets say that i want to delete a part of the resulting list(QuerySelect) how is that done? or exclude certain elements from the query? #Edited result = users.select(); for element in result: for name in list: if(element.name == name): removeThisElement() i want...

Peewee throws KeyError when trying to add user defined operator

python,orm,flask,peewee,keyerror
I followed the short guide in the peewee docs on how to add user defined operators, but when I try to do it, it gives me a KeyError. from peewee import * from peewee import OP from peewee import Expression db = MySQLDatabase(app.config['MYSQL_DATABASE_DB'], host=app.config['MYSQL_DATABASE_HOST'], user=app.config['MYSQL_DATABASE_USER'], passwd=app.config['MYSQL_DATABASE_PASSWORD']) OP['MOD'] = 'mod' def...

how to join two model of two seperated database python peewee

python,mysql,peewee
I'm using peewee to use Mysql database. import peewee db_1 = peewee.MySQLDatabase('db_1', **{'user': 'root'}) db_2 = peewee.MySQLDatabase('db_2', **{'user': 'root'}) class User(peewee.Model): id = peewee.PrimaryKeyField() username = peewee.CharField() class Meta: database = db_1 class Tweet(peewee.Model): id = peewee.PrimaryKeyField() tweet = peewee.CharField() user = peewee.IntegerField(db_column='user_id') class Meta: database = db_2 I want...

How to use Peewee with Tornado perfectly

python,tornado,peewee
I'm useing peewee with my tornado webapp,when I read peewee's document,I found: Adding Request Hooks When building web-applications, it is very important that you manage your database connections correctly. In this section I will describe how to add hooks to your web app to ensure the database connection is handled...

Python peewee save() doesn't work as expected

python,mysql,upsert,peewee
I'm inserting/updating objects into a MySQL database using the peewee ORM for Python. I have a model like this: class Person(Model): person_id = CharField(primary_key=True) name = CharField() I create the objects/rows with a loop, and each time through the loop have a dictionary like: pd = {"name":"Alice","person_id":"A123456"} Then I try...

Aggregate records with peewee and Python

python,mysql,peewee
I'm trying to learn Python and have problem to understand how to use the aggregate functions with peewee. In my code I first do imports like: import sys from datetime import datetime, timedelta from peewee import * from database import (db_init, MF_Djur, MF_Logg, MF_Senaste_Koll, MF_Foderspec) To test if peewee and...

Counting Active connections in peewee ORM

python-2.7,peewee
I am using Python's peewee ORM with MYSQL. I want to list the active connections for the PooledDatabase. Is there any way to list..?

Formatting dates and time with Peewee and SQLite

python,sqlite,datetime,peewee
I'm using Peewee to access a SQLite DB. How can I save a timestamp in the following format? '%Y-%m-%d %H:%M:%S' # year-month-day hour-minute-second (basically: just crop out the microseconds which are present by default) EDIT: I was able to make this work, using the following in the class definition: created...

How can I detect if a user tries to upvote once again?

python,flask,peewee
I'm currently in the process of implementing an upvoting system ( no down voting system will be used in the app). I managed to create an upvote property to the Post model in my app. The default for that property is 0 as shown here: models.py class User(UserMixin, Model): username...

Python - peewee - Debugging statements - where are the errors logged

python,mysql,try-catch,peewee
I have just started to use peewee in python. But as i am saving table data using .save() function. There is an error in the line. and control does not go to the next line. Just wanted to know how can know what the error is. Although i have narrowed...

Set strict sql mode in peewee

python,mysql,peewee
I'd like to force ENUM constraints in my mySQL database. To do that, it is suggested I use "strict" sql mode. In an interactive prompt, this can be set with one of: SET GLOBAL sql_mode = 'STRICT_ALL_TABLES'; SET SESSION sql_mode = 'STRICT_ALL_TABLES'; Or at server startup with: --sql-mode="STRICT_ALL_TABLES" Or in...

Relational Mapping using Peewee

python,data-modeling,peewee
I'm new to relational databases and I'm quite confused on how should I create the models. What I need need to get done is to filter the posts content through the language choice and to do that I need to create a relational database. My doubt comes when deciding how...

Peewee Model keyword can't be an expression on Update

python,orm,model,sql-update,peewee
As you can see from below I am trying to update a record but for some reason I am getting these errors. I have been following the Peewee documentation, and I found a few others who have the same issues but not with Djano's ORM not Peewee. I tried to...