ConsumerAdvice
クラスをインスタンス化しようとするとこのエラーが発生します。SQLAlchemy ForeignKeyがテーブルを見つけることができません
Foreign key associated with column 'tbConsumerAdvice.ConsumerAdviceCategory_ID'
could not find table 'tbConsumerAdviceCategories' with which to generate a
foreign key to target column 'ID_ConsumerAdviceCategories'
class ConsumerAdviceCategory(Base):
__tablename__ = 'tbConsumerAdviceCategories'
__table_args__ = {'schema':'dbo'}
ID_ConsumerAdviceCategories = Column(INTEGER, Sequence('idcac'),\
primary_key=True)
Name = Column(VARCHAR(50), nullable=False)
def __init__(self,Name):
self.Name = Name
def __repr__(self):
return "< ConsumerAdviceCategory ('%s') >" % self.Name
class ConsumerAdvice(Base):
__tablename__ = 'tbConsumerAdvice'
__table_args__ = {'schema':'dbo'}
ID_ConsumerAdvice = Column(INTEGER, Sequence('idconsumeradvice'),\
primary_key=True)
ConsumerAdviceCategory_ID = Column(INTEGER,\
ForeignKey('tbConsumerAdviceCategories.ID_ConsumerAdviceCategories'))
Name = Column(VARCHAR(50), nullable=False)
Category_SubID = Column(INTEGER)
ConsumerAdviceCategory = relationship("ConsumerAdviceCategory",\
backref=backref('ConsumerAdvices'))
def __init__(self,Name):
self.Name = Name
def __repr__(self):
return "< ConsumerAdvice ('%s') >" % self.Name
理由はわかりませんが、 '__table_args__'から' schema'を削除しても動作します(SQLiteでテスト済み)。どのRDBMSを使用していますか? – van
...スキーマを含むFKを定義しようとしています: 'dbo.tbConsumerAdviceCategories.ID_ConsumerAdviceCategories' – van
@vanそれはMSSQLであり、FK定義にスキーマを追加すると機能しました!たくさんのKUDOS ..あなたは答えを追加できるので、答えをマークすることができますか? – MFB