我正在尝试Alembic
第一次使用并想使用此处--autogenerate
描述的功能
我的项目结构看起来像
project/
configuration/
__init__.py
dev.py
test.py
core/
app/
models/
__init__.py
user.py
db/
alembic/
versions/
env.py
alembic.ini
我正在使用Flask
andSQLAlchemy
和他们的Flask-SQLAlchemy
扩展。我的模型User
看起来像
class User(UserMixin, db.Model):
__tablename__ = 'users'
# noinspection PyShadowingBuiltins
uuid = Column('uuid', GUID(), default=uuid.uuid4, primary_key=True,
unique=True)
email = Column('email', String, nullable=False, unique=True)
_password = Column('password', String, nullable=False)
created_on = Column('created_on', sa.types.DateTime(timezone=True),
default=datetime.utcnow())
last_login = Column('last_login', sa.types.DateTime(timezone=True),
onupdate=datetime.utcnow())
如此处所述,我修改env.py
为看起来像
from configuration import app
alembic_config = config.get_section(config.config_ini_section)
alembic_config['sqlalchemy.url'] = app.config['SQLALCHEMY_DATABASE_URI']
engine = engine_from_config(
alembic_config,
prefix='sqlalchemy.',
poolclass=pool.NullPool)
和
from configuration import db
target_metadata = db.metadata
configuration.__init__py
看起来像哪里
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
import dev
app = Flask(__name__)
app.config.from_envvar('SETTINGS_PT')
db = SQLAlchemy(app)
现在当我运行迁移时
$alembic revision --autogenerate -m "Added user table"
INFO [alembic.migration] Context impl PostgresqlImpl.
INFO [alembic.migration] Will assume transactional DDL.
Generating /Users/me/IdeaProjects/project/db/alembic/versions/55a9d5
35d8ae_added_user_table.py...done
但文件alembic/versions/55a9d5
有空upgrade()
和downgrade()
方法
"""Added user table
Revision ID: 1b62a62eef0d
Revises: None
Create Date: 2013-03-27 06:37:08.314177
"""
# revision identifiers, used by Alembic.
revision = '1b62a62eef0d'
down_revision = None
from alembic import op
import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
pass
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
pass
### end Alembic commands ###
怎么就看不懂有新User
机型了?请帮忙