所以我最近从 sqlite 更改为 postgres,以便我可以将我的网站推送到 heroku。我遇到的问题是表格现在乱七八糟地建起来了?
class Data(Base):
__tablename__ = 'data'
id = Column(Integer, autoincrement=True, primary_key=True)
data_type = Column(Integer, primary_key=True, unique=True)
value = Column(Text, primary_key=True, unique=True)
range_lower = Column(Integer)
range_upper = Column(Integer)
gold = Column(Boolean)
def __init__(self, data_type, value, range_lower=0, range_upper=0, gold=False):
self.data_type = data_type
self.value = value
self.range_lower = range_lower
self.range_upper = range_upper
self.gold = gold
class Page(Base):
__tablename__ = 'page'
id = Column(Integer, autoincrement=True, primary_key=True)
data_type = Column(Integer, ForeignKey('data.data_type'))
description = Column(Text)
annotations_per_page = Column(Integer)
uses_gold = Column(Boolean)
def __init__(self, data_type, description='default description', annotations_per_page=1, uses_gold=False):
self.data_type = data_type
self.description = description
self.annotations_per_page = annotations_per_page
self.uses_gold = uses_gold
我遇到的问题是 sqlalchemy/pyramid 或 python setup.py 生成的任何填充脚本在这些类型的项目之一上开发,试图在表数据之前创建表页。由于 Page 中有依赖于 Table 的外键,因此这是失败的。我在文档中找不到任何关于此问题的提及,任何见解将不胜感激。
-山姆