Creating tables with pylons and SQLAlchemy

I use SQLAlchemy, and I can create the tables that I defined in / model / __init__.py, but I 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 that are defined and displayed in /model/profile.py

To create the tables that I run:

paster setup-app development.ini

But my problem is that the tables that I defined in / model / __init__.py are created correctly, 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 file so that all my tables can be created?

Thanks for the help!

+3
source share
3 answers

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

  • Define tables and classes in profile.py
  • In __init__.pyadd from profile import *afterdef init_model
  • Then I added all the definitions of my cartographer. Saving them all in the initialization file solved some problems that I encountered between tables defined in different files.

In addition, since then I created projects using the declarative method and did not need to define the display in the initialization file.

+5
source

init.py from models.meta . Pylons default setup_app , , model.meta .

0

If you are using a declarative style, be sure to use Base.meta to generate the tables.

0
source

Source: https://habr.com/ru/post/1718618/


All Articles