synic
synic

Reputation: 26678

SQLAlchemy - show creation statement with indexes

I am working with a database system that will require me to run the CREATE TABLE manually on several nodes. This means I need to be able to obtain the CREATE statement, complete with indexes.

The following works to get the base schema:

from calendars import models
from app import db
from sqlalchemy import CreateTable

print(CreateTable(models.Calendar.__table__).compile(db.engine))

However, it does NOT print constraints or indexes.

How do I also obtain those?

Upvotes: 0

Views: 80

Answers (1)

talhasch
talhasch

Reputation: 367

if you set sqlalchemy logging to debug, you can read statements from logs.

import logging
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)

Upvotes: 1

Related Questions