peewee

Python peewee save() doesn't work as expected

ⅰ亾dé卋堺 提交于 2019-12-10 15:16:42
问题 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 creating an object and saving it. po = Person() for key,value in pd.items(): setattr(po,key,value) po.save() This takes a while to execute, and runs without

How to use peewee limit()?

此生再无相见时 提交于 2019-12-10 14:22:11
问题 With Peewee I'm trying to use limit as follows: one_ticket = Ticket.select().limit(1) print one_ticket.count() This prints out 5 however. Does anybody know what's wrong here? 回答1: Try running peewee in debug mode, which is actually just setting up the python logging module to handle logging.DEBUG level items: import logging logging.basicConfig( format='[%(asctime)-15s] [%(name)s] %(levelname)s]: %(message)s', level=logging.DEBUG ) # From here, you can now perform your query, and you should

How to do query with `WHERE value IN list` in the Python Peewee ORM?

霸气de小男生 提交于 2019-12-10 02:02:16
问题 I'm using the (awesome) Python Peewee ORM for my Flask project, but I now got stuck trying to do a query with a where value in ['a', 'b', 'c'] . I tried doing it as follows: MyModel.select().where(MyModel.sell_currency in ['BTC', 'LTC']) But unfortunately it returns all records in the DB. Any ideas how I could do this? 回答1: The docs has the answer: x << y will perform x IN y, where y is a list or query . So the final query will look like: MyModel.select().where(MyModel.sell_currency << ['BTC'

Peewee - Can't connect to MySQL server on host

蓝咒 提交于 2019-12-07 13:04:36
问题 I'm developing a Flask based python app using the peewee ORM. I was initially connecting to the database that was being stored locally on my machine and I'm now trying to transition to connecting to the db remotely. I've set up the database in phpmyadmin via my server's cpanel section. The Issue I've set up my IP address to be able to remotely access my databases but I am getting the following error when I attempt to connect to the database: Traceback (most recent call last): File "app.py",

Peewee MySQL server has gone away

放肆的年华 提交于 2019-12-07 09:21:17
问题 I use flask and peewee. Sometimes peewee throws this error MySQL server has gone away (error(32, 'Broken pipe')) Peewee database connection db = PooledMySQLDatabase(database,**{ "passwd": password, "user": user, "max_connections":None,"stale_timeout":None, "threadlocals" : True }) @app.before_request def before_request(): db.connect() @app.teardown_request def teardown_request(exception): db.close() After mysql error that "MySQL server has gone away (error(32, 'Broken pipe'))", select queries

How to query several similar databases using Peewee?

戏子无情 提交于 2019-12-06 14:22:11
I'm stuck with a problem about querying multiple databases using Peewee: I have 2 existing mysql databases (let's name them A and B) (Structures are similar because it's two Bugzilla databases) I generate models (modelsA.py and modelsB.py) using Pwiz I write this code: . from modelsA import * from modelsB import * The problem is: as the classes in modelsB are (sometimes) the same than modelsA, modelsB classes "overwrite" modelsA classes, making impossible to query A. Besides, I don't understand how to query one of the specific database. For example, with this code: c = Customers.get(Customers

Peewee - Can't connect to MySQL server on host

拥有回忆 提交于 2019-12-06 03:46:59
I'm developing a Flask based python app using the peewee ORM. I was initially connecting to the database that was being stored locally on my machine and I'm now trying to transition to connecting to the db remotely. I've set up the database in phpmyadmin via my server's cpanel section. The Issue I've set up my IP address to be able to remotely access my databases but I am getting the following error when I attempt to connect to the database: Traceback (most recent call last): File "app.py", line 294, in <module> models.initialize() File "/Users/wyssuser/Desktop/dscraper/models.py", line 145,

Python and Postgresql: OperationalError: fe_sendauth: no password supplied

自闭症网瘾萝莉.ら 提交于 2019-12-05 23:28:49
I know there are a lot of similar questions on StackOverflow, but I have read and re-read them, and I cannot seem to solve my particular issue. I am developing a Python application that uses Peewee and Psycopg2 to access PostGresQL databases. This is all being run in an Ubuntu Vagrant Virtual Machine. I keep getting this error when I try to add a user via Python: peewee.OperationalError: fe_sendauth: no password supplied Here is the code where I try to add a user : def add_user(user, password): """ :param username: :param password: :return: """ try: #add user to admin user table

Make primary-key fields editable in Flask-Admin

孤人 提交于 2019-12-05 20:57:09
I am using Flask-Admin for my Flask-based project. In it, I have some models (using peewee) where the primary-key is user-set, such as username for a User . However Flask-Admin is not showing these fields in the model's create/edit pages. Now, when I try to create a new user, the "Save" button gives a peewee.UserDoesNotExist error, and the "Save & Add" says "Record successfully created" twice but doesn't actually do anything. I had extended the save() method to auto-generate the username from the name if it's unset, but the problem persisted even when I removed the overriding. The code... Here

Custom sqlite database for unit tests for code using peewee ORM

╄→尐↘猪︶ㄣ 提交于 2019-12-05 16:56:35
问题 I am trying to implement a many-to-many scenario using peewee python ORM and I'd like some unit tests. Peewee tutorial is great but it assumes that database is defined at module level then all models are using it. My situation is different: I don't have a source code file (a module from python's point of view) with tests which I run explicitly, I am using nose which collects tests from that file and runs them. How do I use a custom database only for models instantiated in tests (which are