Fix Python – Multiple columns index when using the declarative ORM extension of sqlalchemy

According to the documentation and the comments in the sqlalchemy.Column class, we should use the class sqlalchemy.schema.Index to specify an index that contains multiple columns.
However, the example shows how to do it by directly using the Table object like this:
meta = MetaData()
mytable = Table(‘mytable’, meta,
# an indexed column, with in….

Fix Python – How to reset db in Django? I get a command ‘reset’ not found error

Following this Django by Example tutotrial here:
The tutorial says:

“This changes our table layout and we’ll have to ask Django to reset
and recreate tables: reset todo; syncdb”

though, when I run reset todo, I get the error:
$ python reset todo ….

Fix Python – What’s the difference between MySQLdb, mysqlclient and MySQL connector/Python?

So I’ve been trying to do some database update with python and while setting up the whole dev environment, I came across these three things which made me dizzy.

There’s MySQLdb
There’s mysqlclient
And then there’s a mysql connector python

What’s each of them, the difference and where to use them? Thanks

Fix Python – SQLAlchemy: how to filter date field?

Here is model:
class User(Base):

birthday = Column(Date, index=True) #in database it’s like ‘1987-01-17’

I want to filter between two dates, for example to choose all users in interval 18-30 years.
How to implement it with SQLAlchemy?
I think of:
query = DBSession.query(User).filter(
and_(User.birthday >= ‘1988-01-17’, U….

Fix Python – How to move a model between two Django apps (Django 1.7)

So about a year ago I started a project and like all new developers I didn’t really focus too much on the structure, however now I am further along with Django it has started to appear that my project layout mainly my models are horrible in structure.
I have models mainly held in a single app and really most of these models should be in their own ….

Fix Python – SQLAlchemy: cascade delete

I must be missing something trivial with SQLAlchemy’s cascade options because I cannot get a simple cascade delete to operate correctly — if a parent element is a deleted, the children persist, with null foreign keys.
I’ve put a concise test case here:
from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.orm import relationship