db = create_engine('mysql://user:pass@localhost/db?charset=utf8')
References :
python - How do I get SQLAlchemy to correctly insert a unicode ellipsis into a mySQL table? - Stack Overflow
db = create_engine('mysql://user:pass@localhost/db?charset=utf8')
with app.app_context(): db.create_all()
engine = create_engine('mysql://root:password@localhost/test?charset=utf8&use_unicode=0')
seats = Seat.query.filter(Seat.invite != None).all()
References :
ython - flask sqlalchemy querying a column with not equals - Stack Overflow
直接使用 db.create_all() 會出錯,改成以下
with app.app_context(): db.create_all()
import os
SQLALCHEMY_DATABASE_URI = os.environ['OPENSHIFT_POSTGRESQL_DB_URL']
import os
SQLALCHEMY_DATABASE_URI = os.environ['OPENSHIFT_MYSQL_DB_URL']
sl = DBSession.query(Puesto.id).filter(Puesto.locales_id == id).subquery() DBSession.query(Servicio).filter(Servicio.puestos_id.in_(sl)) \ .delete(synchronize_session='fetch')
user = db.session.execute(Users.__table__.insert(data))
db.session.commit()
print user.lastrowid
# apt-get install libmysqlclient-dev
# pip install MySQL-python
from sqlalchemy.orm import relation
owners = relation('User', order_by='User.id', uselist=True, backref='addresses')
from sqlalchemy.schema import Column, ForeignKey
address_id = Column(Integer, ForeignKey('addresses.id'))
Table(
'table_name', metadata,
Column('id', None, nullable=False),
Column('email', None, nullable=False),
PrimaryKeyConstraint('id', 'email'),
)
Reference :
python - Creating container relationship in declarative SQLAlchemy - Stack Overflow