【发布时间】:2021-05-13 10:38:46
【问题描述】:
我使用sqlalchemy 的 ORM 库与我们应用程序的其中一个数据库进行交互。在一台主机上,应用实例的数据库后端是 PostgreSQL,而在另一台主机上,由于历史原因,我们使用 MySQL。
两个后端的模式(和关系)相同,但 PostgreSQL 中的表名和列名是小写的,而在 MySQL 中它们是大写的。有什么办法可以在sqlalchemy 中调整我的架构,这样我就不需要复制代码了?
以下是我的架构示例。提示,该应用程序是一个 Confluence wiki ;)
from sqlalchemy import (
BigInteger,
Column,
DateTime,
String,
)
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Space(Base):
__tablename__ = 'spaces'
spaceid = Column(BigInteger, primary_key=True)
spacename = Column(String(255))
spacekey = Column(String(255), nullable=False, unique=True)
lowerspacekey = Column(String(255), nullable=False, index=True)
spacedescid = Column(BigInteger, index=True)
homepage = Column(BigInteger, index=True)
creator = Column(String(255), index=True)
creationdate = Column(DateTime, index=True)
lastmodifier = Column(String(255), index=True)
lastmoddate = Column(DateTime)
spacetype = Column(String(255))
spacestatus = Column(String(255), index=True)
【问题讨论】:
-
你能自动加载表格吗?也许这是一个解决方案stackoverflow.com/questions/9383837/…
标签: mysql postgresql sqlalchemy confluence