views:

462

answers:

3

I'm using SQLAlchemy and I can create tables that I have defined in /model/__init__.py but I have defined my classes, tables and their mappings in other files found in the /model directory.

For example I have a profile class and a profile table which are defined and mapped in /model/profile.py

To create the tables I run:

paster setup-app development.ini

But my problem is that the tables that I have defined in /model/__init__.py are created properly but the table definitions found in /model/profile.py are not created. How can I execute the table definitions found in the /model/profile.py so that all my tables can be created?

Thanks for the help!

A: 

Just import your other table's modules in your init.py, and use metadata object from models.meta in other files. Pylons default setup_app function creates all tables found in metadata object from model.meta after importing it.

abbot
A: 

If you are using declarative style, be sure to use Base.meta for tables generation.

iElectric
+2  A: 

I ran into the same problem with my first real Pylons project. The solution that worked for me was this:

  1. Define tables and classes in your profile.py file
  2. In your init.py add "from proifle import *" after your "def init_model"
  3. I then added all of my mapper definitions afterwards. Keeping them all in the init file solved some problems I was having relating between tables defined in different files.

Also, I've since created projects using the declarative method and didn't need to define the mapping in the init file.

dwelch
Sweet Christmas, thank you. I've been having a devil of a time with Pylons because I keep forgetting how to get create_all() to _work._
Sean M