On 02/28/2014 11:58 PM, Chung WONG wrote:
I have a *models.py* that contains 10 classes. And I am trying to move
all classes out of that file and put each class into its own file
under a models package.
I am using the alternative(at bottom of page) method mentioned here
<https://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/database/sqlalchemy.html#importing-all-sqlalchemy-models>,
but I don't know how it works for initialise db script as it is using
*config.scan()*
However, when i ran *bin/initialize_bug_db development.in *to
initialise the database, it threw such as :
sqlalchemy.exc.InvalidRequestError: When initializing mapper
Mapper|User|users, expression 'TopicUser' failed to locate a name
("name 'TopicUser' is not defined"). If this is a class name, consider
adding this relationship() to the <class 'bug.models.user.User'> class
after both dependent classes have been defined.
which was caused by something like *topics =
relationship('TopicUser', backref="user", lazy='dynamic')*
and
sqlalchemy.exc.NoReferencedTableError: Foreign key associated with
column 'notifications.topic_id' could not find table 'topics' with
which to generate a foreign key to target column 'id'
which was caused by something like *topic_id=Column(Integer,
ForeignKey('topics.id'))*
I am wondering how you guys organise the model files. Maybe there is a
better way?
Thanks.
--
You received this message because you are subscribed to the Google
Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/groups/opt_out.
One that has worked for me in the past is having the fs structure as this:
models/
__init__.py
....
and then in the models/__init__.py:
def includeme(config):
settings = config.get_settings()
engine = sa.engine_from_config(settings, 'sqlalchemy.')
DB.configure(bind=engine)
BASE.metadata.bind = engine
and in your app main:
config = Configurator(settings=settings)
config.include('foo.models')
HTH.
AM
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/groups/opt_out.