Trouble getting started with autogen migrations...?

3,096 views
Skip to first unread message

Doug Linder

unread,
Jun 20, 2013, 7:33:53 AM6/20/13
to sqlalchem...@googlegroups.com
I seem to be having some trouble with my auto gen configurations for alembic.

When I try to run: alembic revision --autogenerate -m "Initial config"

I get:

Traceback (most recent call last):
  File "/usr/local/bin/alembic", line 8, in <module>
    load_entry_point('alembic==0.5.0', 'console_scripts', 'alembic')()
  File "/Library/Python/2.7/site-packages/alembic/config.py", line 265, in main
    CommandLine(prog=prog).main(argv=argv)
  File "/Library/Python/2.7/site-packages/alembic/config.py", line 260, in main
    self.run_cmd(cfg, options)
  File "/Library/Python/2.7/site-packages/alembic/config.py", line 247, in run_cmd
    **dict((k, getattr(options, k)) for k in kwarg)
  File "/Library/Python/2.7/site-packages/alembic/command.py", line 96, in revision
    script.run_env()
  File "/Library/Python/2.7/site-packages/alembic/script.py", line 193, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "/Library/Python/2.7/site-packages/alembic/util.py", line 177, in load_python_file
    module = imp.load_source(module_id, path, open(path, 'rb'))
  File "alembic/env.py", line 78, in <module>
    run_migrations_online()
  File "alembic/env.py", line 71, in run_migrations_online
    context.run_migrations()
  File "<string>", line 7, in run_migrations
  File "/Library/Python/2.7/site-packages/alembic/environment.py", line 536, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/Library/Python/2.7/site-packages/alembic/migration.py", line 205, in run_migrations
    self):
  File "/Library/Python/2.7/site-packages/alembic/command.py", line 82, in retrieve_migrations
    autogen._produce_migration_diffs(context, template_args, imports)
  File "/Library/Python/2.7/site-packages/alembic/autogenerate.py", line 127, in _produce_migration_diffs
    include_schemas)
  File "/Library/Python/2.7/site-packages/alembic/autogenerate.py", line 177, in _produce_net_changes
    for table in metadata.sorted_tables])
AttributeError: type object 'Base' has no attribute 'sorted_tables'

Which is weird, because if I put this in my env.py:

from app.model import Base
print("\n\n")
print(Base.metadata.sorted_tables)
print("\n\n")
target_metadata = Base

The output is:

[Table('flash_msg', MetaData(bind=None), Column('id', Integer(), table=<flash_msg>, primary_key=True, nullable=False, default=Sequence('flash_msg_id_seq', metadata=MetaData(bind=None))), Column('created_on', DateTime(), table=<flash_msg>, nullable=False), Column('level', Integer(), table=<flash_msg>, nullable=False), Column('message', String(), table=<flash_msg>, nullable=False), schema=None), Table('prefs', MetaData(bind=None), Column('id', Integer(), table=<prefs>, primary_key=True, nullable=False, default=Sequence('pref_id_seq', metadata=MetaData(bind=None))), Column('key', String(), table=<prefs>, nullable=False), Column('value', String(), table=<prefs>, nullable=False), schema=None)]

INFO  [alembic.migration] Context impl SQLiteImpl.
INFO  [alembic.migration] Will assume non-transactional DDL.

... [same error as above] ...
AttributeError: type object 'Base' has no attribute 'sorted_tables'

Any suggestion what I might be doing wrong?

(I had a hunt around online, but on one else seems to have hit this; FYI I'm using alembic-0.5.0 and sqlalchemy-0.8.1).

Cheers,
Doug.

Michael Bayer

unread,
Jun 20, 2013, 2:52:50 PM6/20/13
to sqlalchem...@googlegroups.com

On Jun 20, 2013, at 7:33 AM, Doug Linder <douglas...@gmail.com> wrote:

> I seem to be having some trouble with my auto gen configurations for alembic.
>
> When I try to run: alembic revision --autogenerate -m "Initial config"
>
> AttributeError: type object 'Base' has no attribute 'sorted_tables'
>
> Which is weird, because if I put this in my env.py:
>
> from app.model import Base
> print("\n\n")
> print(Base.metadata.sorted_tables)
> print("\n\n")
> target_metadata = Base

this needs to say:

target_metadata = Base.metadata


Doug Linder

unread,
Jun 20, 2013, 10:42:24 PM6/20/13
to sqlalchem...@googlegroups.com
aha, thank you for pointing out my ridiculously obvious mistake.
Working perfectly now. :)
Reply all
Reply to author
Forward
0 new messages