How to format a mysql datetime yyyy-mm-dd to dd-mm-yyyy in Python?

My python code retrieves a datetime column from a mySql server database. I can print the datetime as it is stored on the server (ex. 2018-10-22, however I need to print it in a more readable way like …

Python flask-sqlalchemy: Do I have to commit session after a query?

I am writing an app in python flask-sqlalchemy with MySQL DB ( 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 query that could be extended to include additional filters (WHERE etc.). It doesn’t alter the database, it simply reads values from it. You don’t need to commit on a read for precisely that reason – what would you store other than “I just read this data”? Databases are concerned about this in other ways i.e. access permissions and logs.

Python – Connect MySQL through localhost not working but 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 happening. I’m 100% sure my password is correct. I’m using mysql.connector Python file: I’m a bit new to this DB and VPS stuff, so please bear with me if I don’t understand on the first go. Thanks! Answer In addition to @don’s answer I assume

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 same…Thank you! Answer Assuming you want to store some simple information, Sqlite3 does exact what you’re looking for. This is a sql database that is entirely run on a file on the hardrive that the application is running from. But be careful what

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. import mysql.connector import csv mydb = mysql.connector.connect(host=’127.0….

Django filter on OneToOne field appending “_id” and failing

In my Django application I have the following model: Note user is a OneToOneField to my CustomUser table and also the primary key of this table. In, I attempt to query this table with Provider.objects.filter(user=request.user) and get django.db.utils.OperationalError: (1054, “Unknown column ‘appname_provider.user_id’ in ‘field list'”). Checking my MySql database, I see the columns are (user, company_id). So why is Django adding “_id” to user when I try to filter? My CustomUser model: Answer Here’s how I solved this issue: Undo all migrations: rm -rf appname/migrations/0* appname/__pycache__ and in mysql: DELETE FROM django_migrations; Delete the Provider table in mysql: DROP

Use python to turn mysql into json

I want to use python to turn mysql into json, but when I use the following code, the result is json line by line, not a whole set of json Answer You need to pull out the json.dumps() line from the for loop. This is resulting in conversion of into json with each iteration and printing in each iteration. Your code should look like this :

How to store column value from mysql to python variable? [SOLVED]

actually i’m new to learning python and mysql database i have table named TABEL_NILAI in database like this: So i want to Retrieve value NILAI_TRUST from TABEL_NILAI and i want to do some math. here’s code i was made: And giving me error like: so how to retrieve value into python variable in right ways. Please help:( Answer The query will return a iterable of tuples, for example like this: So this line has two problems: x is a tuple, so it can’t be called like x() x is not a string, so it doesn’t have a split method It

How to show more objects in my html with django (queries)

I want to show more queries within my html page but it only shows a single object. I do not know how to add more This is in mysql, html, django1.11 and python 2.7.15 i need add object mapa and competencias. The object alumno i dont have problem Answer User filter instead of get. Because, get returns a single object, but filter returns all matching objects. In your template For Alumnao, For mapa, For competencias,

Authentication plugin ‘caching_sha2_password’ is not supported

I am trying to connect to a MySQL server with python connector. I created a new user lcherukuri with the authentication plugin mysql_native_password. But I got the error mysql.connector.errors….