Frequently Asked Questions
The Frequently Asked Questions section is a growing collection of commonly observed questions to well-known issues.
- Connections / Engines
- How do I configure logging?
- How do I pool database connections? Are my connections pooled?
- How do I pass custom connect arguments to my database API?
- “MySQL Server has gone away”
- “Commands out of sync; you can’t run this command now” / “This result object does not return rows. It has been closed automatically”
- How Do I “Retry” a Statement Execution Automatically?
- Why does SQLAlchemy issue so many ROLLBACKs?
- I am using multiple connections with a SQLite database (typically to test transaction operation), and my test program is not working!
- How do I get at the raw DBAPI connection when using an Engine?
- How do I use engines / connections / sessions with Python multiprocessing, or os.fork()?
- MetaData / Schema
- My program is hanging when I say
table.drop()
/metadata.drop_all()
- Does SQLAlchemy support ALTER TABLE, CREATE VIEW, CREATE TRIGGER, Schema Upgrade Functionality?
- How can I sort Table objects in order of their dependency?
- How can I get the CREATE TABLE/ DROP TABLE output as a string?
- How can I subclass Table/Column to provide certain behaviors/configurations?
- My program is hanging when I say
- SQL Expressions
- ORM Configuration
- How do I map a table that has no primary key?
- How do I configure a Column that is a Python reserved word or similar?
- How do I get a list of all columns, relationships, mapped attributes, etc. given a mapped class?
- I’m getting a warning or error about “Implicitly combining column X under attribute Y”
- I’m using Declarative and setting primaryjoin/secondaryjoin using an
and_()
oror_()
, and I am getting an error message about foreign keys. - Why is
ORDER BY
required withLIMIT
(especially withsubqueryload()
)?
- Performance
- Sessions / Queries
- I’m re-loading data with my Session but it isn’t seeing changes that I committed elsewhere
- “This Session’s transaction has been rolled back due to a previous exception during flush.” (or similar)
- How do I make a Query that always adds a certain filter to every query?
- My Query does not return the same number of objects as query.count() tells me - why?
- I’ve created a mapping against an Outer Join, and while the query returns rows, no objects are returned. Why not?
- I’m using
joinedload()
orlazy=False
to create a JOIN/OUTER JOIN and SQLAlchemy is not constructing the correct query when I try to add a WHERE, ORDER BY, LIMIT, etc. (which relies upon the (OUTER) JOIN) - Query has no
__len__()
, why not? - How Do I use Textual SQL with ORM Queries?
- I’m calling
Session.delete(myobject)
and it isn’t removed from the parent collection! - why isn’t my
__init__()
called when I load objects? - how do I use ON DELETE CASCADE with SA’s ORM?
- I set the “foo_id” attribute on my instance to “7”, but the “foo” attribute is still
None
- shouldn’t it have loaded Foo with id #7? - How do I walk all objects that are related to a given object?
- Is there a way to automagically have only unique keywords (or other kinds of objects) without doing a query for the keyword and getting a reference to the row containing that keyword?
- Why does post_update emit UPDATE in addition to the first UPDATE?
- Third Party Integration Issues
当前内容版权归 SQLAlchemy 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 SQLAlchemy .