Skip to content

Instantly share code, notes, and snippets.

@drewverlee
Created January 13, 2013 17:25
Show Gist options
  • Save drewverlee/4525193 to your computer and use it in GitHub Desktop.
Save drewverlee/4525193 to your computer and use it in GitHub Desktop.
Naming conventions
class SurveySection(db.Model):
"""
Survey_section has a one-to-many relationship with User_survey_section
"""
id = db.Column(db.Integer, primary_key=True)
user_survey_sections = db.relationship('User_survey_section', backref="survey_section",
lazy='dynamic')
name = db.Column(db.String(45))
class UserSurveySection(db.Model):
"""
User_survey_section has a many-to-one relationship with Survey_section
"""
id = db.Column(db.Integer, primary_key=True)
survey_section_id = db.Column(db.Integer, db.ForeignKey('survey_section.id'))
completed_date = db.Column(db.DateTime)
In [13]: User.query.filter_by(email="")
---------------------------------------------------------------------------
InvalidRequestError Traceback (most recent call last)
<ipython-input-13-c505348c33f2> in <module>()
----> 1 User.query.filter_by(email="")
/home/drew/.virtualenvs/staging/local/lib/python2.7/site-packages/flask_sqlalchemy.pyc in __get__(self, obj, type)
392 def __get__(self, obj, type):
393 try:
--> 394 mapper = orm.class_mapper(type)
395 if mapper:
396 return type.query_class(mapper, session=self.sa.session())
/home/drew/.virtualenvs/staging/local/lib/python2.7/site-packages/sqlalchemy/orm/util.pyc in class_mapper(class_, compile)
659
660 if compile and mapperlib.module._new_mappers:
--> 661 mapperlib.configure_mappers()
662 return mapper
663
/home/drew/.virtualenvs/staging/local/lib/python2.7/site-packages/sqlalchemy/orm/mapper.pyc in configure_mappers()
2258 % mapper._configure_failed)
2259 e._configure_failed = mapper._configure_failed
-> 2260 raise e
2261 if not mapper.configured:
2262 try:
InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Original exception was: When initializing mapper Mapper|SurveySection|survey_section, expression 'User_survey_section' failed to locate a name ("name 'User_survey_section' is not defined"). If this is a class name, consider adding this relationship() to the <class 'petalapp.database.models.SurveySection'> class after both dependent classes have been defined.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment