Hi all, I am new to this list.
I try to new table which inherit some columns from existing table, not
all columns.
Sample script like this.
###########################################################################
from sqlalchemy import *
url = "mysql://foo:[EMAIL PROTECTED]/mydb"
engine = create_engine(url, echo=True)
# make first metadata
meta = BoundMetaData(engine)
# get table which already exists
emp = Table('emp', meta, autoload=True)
print list(emp.columns)
# result above
#
[Column('empno',MSSmallInteger(length=3),primary_key=True,nullable=False),
Column('ename',MSString(length=10),primary_key=True,nullable=False),
Column('job',MSString(length=10)), Column('hiredate',MSDate())]
# make second metadata
meta2 = MetaData('emp2')
# copy metadata from first metadata
emp2 = emp.tometadata(meta)
# create second table
emp2.name = 'emp2'
if engine.has_table(emp2.name):
emp2.drop(engine)
emp2.create(engine)
# delete hiredate column
conn = engine.connect()
trans = conn.begin()
engine.execute('ALTER TABLE %s DROP %s' % (emp2.name, "hiredate"))
trans.commit()
###########################################################################
I don't need "hiredate" column, so I execute raw sql method.
But I don't think this is a smart way in ORM system.
Table instance has append_column method, but it has no delete_column or
remove_column method.
Is there bettter way for this ?
- sS
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---