python - SqlAlchemy Migrate Declarative -


i've modified tutorial on sqlalchemy-migrate tutorial declarative syntax pylons pyramid project. can upgrade , downgrade, i'm concerned base.metadata.drop_all(migrate_engine) command below. here migration file:

from sqlalchemy import column sqlalchemy.types import integer, string, datetime sqlalchemy.sql import func sqlalchemy.ext.declarative import declarative_base sqlalchemy.orm import scoped_session, sessionmaker  zope.sqlalchemy import zopetransactionextension  dbsession = scoped_session(sessionmaker(extension=zopetransactionextension())) base = declarative_base()  class user(base):     __tablename__ = 'users'     id = column(integer, primary_key=true)     email = column(string(75), unique=true)     fullname = column(string(60))               password = column(string(51))               last_login = column(datetime)               date_joined = column(datetime, default=func.now())  def upgrade(migrate_engine):     # upgrade operations go here. don't create own engine; bind migrate_engine     # metadata     base.metadata.bind = migrate_engine     base.metadata.create_all(migrate_engine) # dangerous?  def downgrade(migrate_engine):     # operations reverse above upgrade go here.     base.metadata.bind = migrate_engine     base.metadata.drop_all(migrate_engine) # dangerous? 

[edit] question how individually create tables. didn't know question until asking wrong question enough, correct question.

the proper solution on upgrade table , create individually, such:

def upgrade(migrate_engine):     # upgrade operations go here. don't create own engine; bind migrate_engine     # metadata     user.__table__.create(migrate_engine) 

and, downgrading:

def downgrade(migrate_engine):     # operations reverse above upgrade go here.     user.__table__.drop(migrate_engine) 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -