14

I'm running into this error when I attempt to run upgrade for the first time. It seems to be failing on the gender_types enum, even though I have given it a name attribute.

Is there a fix for this? Is there some way to see what SQL is getting generated?

This is my models.py and this is the error I get when I run flask.ext.migrate.upgrade.

class User(UserMixin, db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    first = db.Column(db.String(64))
    last = db.Column(db.String(64))
    dob = db.Column(db.Date)
    street_addr1 = db.Column(db.String(64))
    street_addr2 = db.Column(db.String(64))
    city = db.Column(db.String(64))
    state = db.Column(db.String(2))
    zip = db.Column(db.String(9))
    gender = db.Column(db.Enum('M', 'F', name='gender_types'))
    home_box = db.Column(db.String(32))
    username = db.Column(db.String(64), unique=True, index=True)
    password_hash = db.Column(db.String(128))

    @property
    def password(self):
        raise AttributeError('password is not a readable attribute')

    @password.setter
    def password(self, password):
        self.password_hash = generate_password_hash(password)

    def verify_password(self, password):
        return check_password_hash(self.password_hash, password)
    def __repr__(self):
        return '<User %r>' % self.username

@login_manager.user_loader
def load_user(user_id):
    return User.query.get(int(user_id))

class Competition(db.Model):
    __tablename__ = 'competitions'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(12))

Terminal output:

(venv)Nates-MacBook-Pro-2:competitions nate$ heroku run python manage.py deploy
Running `python manage.py deploy` attached to terminal... up, run.8483
INFO  [alembic.migration] Context impl PostgresqlImpl.
INFO  [alembic.migration] Will assume transactional DDL.
INFO  [alembic.migration] Running upgrade None -> 3c7e6046cf6, initial migration
Traceback (most recent call last):
  File "manage.py", line 36, in <module>
    manager.run()
  File "/app/.heroku/python/lib/python2.7/site-packages/flask_script/__init__.py", line 405, in run
    result = self.handle(sys.argv[0], sys.argv[1:])
  File "/app/.heroku/python/lib/python2.7/site-packages/flask_script/__init__.py", line 384, in handle
    return handle(app, *positional_args, **kwargs)
  File "/app/.heroku/python/lib/python2.7/site-packages/flask_script/commands.py", line 145, in handle
    return self.run(*args, **kwargs)
  File "manage.py", line 25, in deploy
    upgrade()
  File "/app/.heroku/python/lib/python2.7/site-packages/flask_migrate/__init__.py", line 98, in upgrade
    command.upgrade(config, revision, sql = sql, tag = tag)
  File "/app/.heroku/python/lib/python2.7/site-packages/alembic/command.py", line 124, in upgrade
    script.run_env()
  File "/app/.heroku/python/lib/python2.7/site-packages/alembic/script.py", line 199, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "/app/.heroku/python/lib/python2.7/site-packages/alembic/util.py", line 199, in load_python_file
    module = load_module(module_id, path)
  File "/app/.heroku/python/lib/python2.7/site-packages/alembic/compat.py", line 55, in load_module
    mod = imp.load_source(module_id, path, fp)
  File "migrations/env.py", line 72, in <module>
    run_migrations_online()
  File "migrations/env.py", line 65, in run_migrations_online
    context.run_migrations()
  File "<string>", line 7, in run_migrations
  File "/app/.heroku/python/lib/python2.7/site-packages/alembic/environment.py", line 652, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/app/.heroku/python/lib/python2.7/site-packages/alembic/migration.py", line 225, in run_migrations
    change(**kw)
  File "migrations/versions/3c7e6046cf6_initial_migration.py", line 33, in upgrade
    sa.PrimaryKeyConstraint('id')
  File "<string>", line 7, in create_table
  File "/app/.heroku/python/lib/python2.7/site-packages/alembic/operations.py", line 647, in create_table
    self._table(name, *columns, **kw)
  File "/app/.heroku/python/lib/python2.7/site-packages/alembic/ddl/impl.py", line 148, in create_table
    _ddl_runner=self)
  File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/event.py", line 409, in __call__
    fn(*args, **kw)
  File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 404, in __call__
    return getattr(self.target, self.name)(*arg, **kw)
  File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/types.py", line 1933, in _on_table_create
    t._on_table_create(target, bind, **kw)
  File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.py", line 870, in _on_table_create
    self.create(bind=bind, checkfirst=checkfirst)
  File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.py", line 821, in create
    bind.execute(CreateEnumType(self))
  File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 662, in execute
    params)
  File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 714, in _execute_ddl
    compiled = ddl.compile(dialect=dialect)
  File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/sql/expression.py", line 1920, in compile
    return self._compiler(dialect, bind=bind, **kw)
  File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/schema.py", line 2954, in _compiler
    return dialect.ddl_compiler(dialect, self, **kw)
  File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/interfaces.py", line 804, in __init__
    self.string = self.process(self.statement, **compile_kwargs)
  File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/interfaces.py", line 823, in process
    return obj._compiler_dispatch(self, **kwargs)
  File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py", line 80, in _compiler_dispatch
    return meth(self, **kw)
  File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.py", line 1072, in visit_create_enum_type
    self.preparer.format_type(type_),
  File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.py", line 1254, in format_type
    raise exc.CompileError("Postgresql ENUM type requires a name.")
sqlalchemy.exc.CompileError: Postgresql ENUM type requires a name.
2
  • 1
    You can't see the SQL because this is a SQLAlchemy compile error, which happens because it doesn't even know how to emit the SQL. It sounds like the alembic migration did not include the name in the Enum specification; can you check if that's the case in migrations/versions/3c7e6046cf6_initial_migration.py? Commented Jun 17, 2014 at 2:24
  • 1
    I figured out the migrations were old and based on a model that did not include the name attribute in the Enum. Thanks, I regenerated the migrations and it works fine now. Commented Jun 17, 2014 at 2:49

1 Answer 1

18

You need to include name attribute in the Enum, like db.Enum('M', 'F', name='gender_types')

Sign up to request clarification or add additional context in comments.

1 Comment

what you mean ? can you give a more detailed answer ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.