谁能告诉我为什么下面的 DateTime 类型会创建一个“DATE”对象而不是 DateTime(或更恰当地说,是一个 TIMESTAMP 类型),因为我必须强制如下行中的类型:
#!/bin/python
import sqlalchemy
from sqlalchemy import Column, Integer, String, DateTime, Index, MetaData
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy.orm import sessionmaker
from sqlalchemy.dialects import oracle
Base = declarative_base()
import logging
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
class TypeTest(Base):
__tablename__ = "TYPETESTZ"
thisisinteger = Column(Integer, primary_key = True)
thisisnotadatetime = Column(DateTime)
thisisdatetime = Column(oracle.TIMESTAMP)
if __name__ == "__main__":
engine = sqlalchemy.create_engine('oracle://richard:password@xe')
metadata = Base.metadata
metadata.create_all(engine)
日志输出:
INFO:sqlalchemy.engine.base.Engine:SELECT USER FROM DUAL
INFO:sqlalchemy.engine.base.Engine:{}
INFO:sqlalchemy.engine.base.Engine:SELECT table_name FROM all_tables WHERE table_name = :name AND owner = :schema_name
INFO:sqlalchemy.engine.base.Engine:{'name': u'TYPETESTZ', 'schema_name': u'RICHARD'}
INFO:sqlalchemy.engine.base.Engine:
CREATE TABLE "TYPETESTZ" (
thisisinteger INTEGER NOT NULL,
thisisnotadatetime DATE,
thisisdatetime TIMESTAMP,
PRIMARY KEY (thisisinteger)
)
INFO:sqlalchemy.engine.base.Engine:{}
INFO:sqlalchemy.engine.base.Engine:COMMIT