I have put my problem in a small program for easy understanding.
Run this with MySQL.
from sqlalchemy import create_engine, __version__
from sqlalchemy import Table, Column, Integer, String, MetaData,
ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relationship, backref
print "SQLAlchemy Version:", __version__
engine = create_engine('mysql://username:password@localhost/testdb',
echo=True)
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()
metadata = Base.metadata
class LotsOfNames(Base):
__tablename__ = 'lotsofnames'
__table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset':
'utf8'}
id = Column(Integer, primary_key=True)
name = Column(String(255), ForeignKey('
users.name'))
class User(Base):
__tablename__ = 'users'
__table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset':
'utf8'}
id = Column(Integer, primary_key=True)
name = Column(String(255), primary_key=True)
fullname = Column(String(255))
password = Column(String(255))
morenames = relationship(LotsOfNames,
backref=backref('lotsofnames',
order_by=LotsOfNames.id))
User.__table__.drop(bind=engine, checkfirst=True)
LotsOfNames.__table__.drop(bind=engine, checkfirst=True)
metadata.create_all(engine)
On Nov 5, 10:16 am, Richie Ward <
rich...@gmail.com> wrote:
> I think I am using the same declarative_base instance but it is still
> making the tables in the wrong order.
>
> My model is at:
http://bazaar.launchpad.net/~richies/hypernucleus-server/PylonsPortEx...
>
> And here is what happens when I run: paster setup-app development.inihttp://
pastebin.com/VuW7UK3B