I have this code:
from sqlalchemy import Column, Integer, Text, String, TIMESTAMP, Boolean, \
UnicodeText
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.schema import Sequence, ForeignKey, Index
from zope.sqlalchemy import ZopeTransactionExtension
import datetime
DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base = declarative_base()
class Users(Base):
__tablename__ = "user_table"
id = Column(Integer, Sequence('idseq'), primary_key = True)
email = Column(String, unique=True)
ip_addr = Column(String)
created_date = Column(TIMESTAMP(timezone=True), default=datetime.datetime.utcnow)
modified_date = Column(TIMESTAMP(timezone=True), default=datetime.datetime.utcnow)
#Index('user_index',Users.c.email)
How can I
In the alembic's env.py, apart from all the normal and default lines, I have these two lines
from tutorial.models import Base
.
.
.
target_metadata = Base.metadata
My app name is tutorial. And if somehow it is needed I am using Pyramid as the framework. and postgres as the db.
index=True
on your field definition.Index
declaration outside the class definition:
class Users(Base):
__tablename__ = "user_table"
id = Column(Integer, Sequence('idseq'), primary_key=True)
email = Column(String, unique=True)
ip_addr = Column(String)
created_date = Column(TIMESTAMP(timezone=True), default=datetime.datetime.utcnow)
modified_date = Column(TIMESTAMP(timezone=True), default=datetime.datetime.utcnow)
Index('user_index', Users.c.email, Users.c.ip_addr)