$ python schema_migration/manage.py test
Traceback (most recent call last):
File "schema_migration/manage.py", line 2, in <module>
from migrate.versioning.shell import main
File "/Users/gisborne/Documents/iparq/tg2env/lib/python2.6/site-packages/sqlalchemy_migrate-0.5.4-py2.6.egg/migrate/versioning/shell.py", line 7, in <module>
from migrate.versioning.base import *
File "/Users/gisborne/Documents/iparq/tg2env/lib/python2.6/site-packages/sqlalchemy_migrate-0.5.4-py2.6.egg/migrate/versioning/base/__init__.py", line 5, in <module>
from const import databases,operations
File "/Users/gisborne/Documents/iparq/tg2env/lib/python2.6/site-packages/sqlalchemy_migrate-0.5.4-py2.6.egg/migrate/versioning/base/const.py", line 7, in <module>
from sqlalchemy.util import OrderedDict
ImportError: No module named sqlalchemy.util
Here is the migration I am trying to add:
from sqlalchemy import *
from migrate import *
metadata = MetaData(migrate_engine)
users_table = Table("tg_user", metadata,
Column("user_id", Integer, autoincrement=True, primary_key=True),
Column("user_name", Unicode(16), unique=True, nullable=False),
Column("email_address", Unicode(255), unique=True, nullable=False, info={'rum': {'field':'Email'}}),
Column("display_name", Unicode(255)),
Column("password", Unicode(80), info={'rum': {'field':'Password'}}),
Column("created", DateTime, default=datetime.now),
Column("account_id", Integer, ForeignKey('accounts.id')))
column = Column("activated", DateTime)
def upgrade():
# Upgrade operations go here. Don't create your own engine; use the engine
# named 'migrate_engine' imported from migrate.
column.create(users_table)
def downgrade():
# Operations to reverse the above upgrade go here.
users_table.activated.drop()
Also, there doesn't appear to be a whole lot of documentation on migrations. Am I right in thinking that I need to copy the extant table definition into a migration before I can modify it? Is there a good reason for that?
Despite what it says at the top of the official documentation here:
<http://packages.python.org/sqlalchemy-migrate/changeset.html#column>
when I do col.create(table) (here is the code: <http://paste.chrisarndt.de/paste/69624c289e4f482e975a9961d4937d50>), I get:
AttributeError: 'Column' object has no attribute 'create'
So now I'm just doing table.create() after defining the table how I want (I'm having trouble working this out definitively, but I think that's how SQLAlchemy does schema changes). That's here: <http://paste.chrisarndt.de/paste/620eb622bb9b47fbad4667f7e54807c7>. I am absolutely certain that my database has a table "accounts", with a column "id", yet this gives me:
sqlalchemy.exc.NoReferencedTableError: Could not find table 'accounts' with which to generate a foreign key