I am learning python and sqlalchemy and modelled this relationship between shops and locale. I get the error:
InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Triggering mapper: 'Mapper|Shop|shop'. Original exception was: Mapper 'Mapper|Locale|locale' has no property 'shop'
when I try to retrieve a lolcale from the db.
from sqlalchemy import Column, ForeignKey, PrimaryKeyConstraint, String
from sqlalchemy.orm import relationship
class Shop(maria.Base):
__tablename__ = 'shop'
__table_args__ = {'extend_existing': True }
name = Column(String(25), primary_key=True)
locale = Column(String, ForeignKey('locale.country'), primary_key=True)
url = Column(String, nullable=False)
country = relationship("Locale", back_populates='shop')
def __repr__(self):
return "{\n\tname:'%s',\n\tlocale:'%s',\n\turl:'%s'\n}" % (self.name, self.locale, self.url)
class Locale(maria.Base):
__tablename__ = 'locale'
__table_args__ = {'extend_existing': True}
country = Column(String(50), primary_key=True)
code = Column(String(11), primary_key=True)
def __repr__(self):
return "{\n\tcountry:'%s',\n\tcode:'%s'\n}" % (self.country, self.code)