I am writing an app in python flask-sqlalchemy with MySQL DB (https://flask-sqlalchemy.palletsprojects.com/en/2.x/) and I am wondering if I have to make “db.session.commit() or db.session.rollback()” after GET call, which only query DB . For example: Answer orders = Order.query.all() is a SELECT q…
Tag: mysql
How to support Command Time out in mysql version 5.6? I am looking for a CommandTimeout option similar to that of ADO .NET but in python
I am new to python and would like to do what ADO .NET CommandTimeout property does (setting the execution time for a query) in mysql (5.6). I am looking for any in-built python libraries that may support it by default (I have tried pymysql, pyodbc and mysql.connector) or what could the best way to do this, in…
MySQL: Update multiple rows with random values
I have a table called rainfall. It has 2 columns (sensorID, area, time, rainfall, redalert) I want to fill the time column with random times in intervals of 5 minutes (e.g 12:55, 04:30, 07:45) . I managed to get the random times by using this Python code: The problem is that this code fill all rows in time wi…
Python – Connect MySQL through localhost not working but 127.0.0.1 is working?
I just setup a VPS with a Mysql Database on it. I’m able to log into the database in the SSH terminal with mysql -uroot -p however, the python file shown below is unable to form a connection, and errors with Access denied for root@localhost (using password: YES). I’m confused as to why this is hap…
Python Database that stays with the program
So mysql works great when you log into your mysql database program on that device but what if you want to move the program to another device, the connected databases wont work… Is there anyway to have the database somehow within the python file, so that when I move it to other devices it will act the sa…
Import Data from .csv file into mysql using python
I am trying to import data from two columns of a .csv file (time hh:mm, float). I created a database and a table in mysql. If I run the program with executemany(), result is the following: [’01:00′, ‘1’] ‘-1 was inserted.’ and after this I do get the error code: Not all par…
CSV data to MySQL table
I am trying to insert rows from a csv file into a MySQL table. I tried this code Nb: tab is a table with two columns name (varchar 20) and nb_cases (double) I get this error: DataError: (1265, “Data truncated for column ‘nb_cases’ at row 1”) Answer your number doesn’t fit it must…
Why BINARY usage in SQLAlchemy with Python3 cause a TypeError: ‘string argument without an encoding’
I read a lot of similar questions but none of the clearly answer my issue. I’m using sqlalchemy-utils EncryptedType on a mysql table column. The table creation and the insert is ok, but when I’m trying to do a query a receive: I found out that this error occurs only using python 3, not using pytho…
MySQLInterfaceError: Python type list cannot be converted
it returns : MySQLInterfaceError: Python type list cannot be converted Answer One solution is to convert list to string like this.
Django 3.x error: ‘mysql.connector.django’ isn’t an available database backend
Having recently upgraded a Django project from 2.x to 3.x, I noticed that the mysql.connector.django backend (from mysql-connector-python) no longer works. The last version of Django that it works with is 2.2.11. It breaks with 3.0. I am using mysql-connector-python==8.0.19. When running manage.py runserver, …