Pylons/pyramid — Issue #359: 'alchemy'  scaffold documentation
Author: mikeorr
Created: 2011-11-26 01:19:54+00:00
State: open

The 'alchemy' scaffold in Pyramid 1.3 doesn't run out of the box. The first request fails with "OperationalError: (OperationalError) no such table: models u'SELECT models.id AS models_id". The user should run "python -m myapp.scripts.populate" and then "pserve", but that doesn't help because the table is never actually created. Populate's main() function is never called.

1) At the end of pyramid/scaffolds/alchemy/+package+/scripts/populate.py_tmpl, add:

if __name__ == "__main__": main()

2) In the manual on the scaffolds page, explain that 'populate' is required when using the 'achemy' scaffold.
http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/project.html#scaffolds-included-with-pyramid

3) I'd suggest enabling logging in 'populate'. (The default development.ini logs SQL commands, which would confirm that the table is being created.)

import logging.config
# After the 'settings =' line in main().
logging.config.fileConfig(config_filename)

4) Consider whether to replace paste.deploy.loadwsgi() in populate.py with pyramid.paster.get_app(). The function was added so that scripts wouldn't have to call obscure, undocumented PasteDeploy functions. It would also be future-proof in case Pyramid later moves away from PasteDeploy. However, the return value may be different (the 'app' object instead of the config dict?), and that may throw off the script. Also, consider whether 'pyramid.paster' is the best name for this module now that 'paster' has been retired from Pyramid.