• <tfoot id='HQAfk'></tfoot>

    <small id='HQAfk'></small><noframes id='HQAfk'>

  • <i id='HQAfk'><tr id='HQAfk'><dt id='HQAfk'><q id='HQAfk'><span id='HQAfk'><b id='HQAfk'><form id='HQAfk'><ins id='HQAfk'></ins><ul id='HQAfk'></ul><sub id='HQAfk'></sub></form><legend id='HQAfk'></legend><bdo id='HQAfk'><pre id='HQAfk'><center id='HQAfk'></center></pre></bdo></b><th id='HQAfk'></th></span></q></dt></tr></i><div id='HQAfk'><tfoot id='HQAfk'></tfoot><dl id='HQAfk'><fieldset id='HQAfk'></fieldset></dl></div>
        <bdo id='HQAfk'></bdo><ul id='HQAfk'></ul>
      <legend id='HQAfk'><style id='HQAfk'><dir id='HQAfk'><q id='HQAfk'></q></dir></style></legend>

        Alembic --autogenerate 产生空迁移

        Alembic --autogenerate producing empty migration(Alembic --autogenerate 产生空迁移)

          1. <small id='GksiS'></small><noframes id='GksiS'>

                  <tbody id='GksiS'></tbody>
                <legend id='GksiS'><style id='GksiS'><dir id='GksiS'><q id='GksiS'></q></dir></style></legend>

                  <bdo id='GksiS'></bdo><ul id='GksiS'></ul>

                • <tfoot id='GksiS'></tfoot>
                • <i id='GksiS'><tr id='GksiS'><dt id='GksiS'><q id='GksiS'><span id='GksiS'><b id='GksiS'><form id='GksiS'><ins id='GksiS'></ins><ul id='GksiS'></ul><sub id='GksiS'></sub></form><legend id='GksiS'></legend><bdo id='GksiS'><pre id='GksiS'><center id='GksiS'></center></pre></bdo></b><th id='GksiS'></th></span></q></dt></tr></i><div id='GksiS'><tfoot id='GksiS'></tfoot><dl id='GksiS'><fieldset id='GksiS'></fieldset></dl></div>
                  本文介绍了Alembic --autogenerate 产生空迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我第一次尝试使用 Alembic 并想使用 --autogenerate 功能/en/latest/tutorial.html#auto-generating-migrations" rel="noreferrer">这里

                  I am trying to use Alembic for the first time and want to use --autogenerate feature described here

                  我的项目结构是这样的

                  project/
                         configuration/
                                      __init__.py
                                      dev.py
                                      test.py
                         core/
                             app/
                                models/
                                      __init__.py
                                      user.py
                         db/
                            alembic/
                                    versions/
                                    env.py
                            alembic.ini
                  

                  我正在使用 FlaskSQLAlchemy 以及它们的 Flask-SQLAlchemy 扩展.我的模型 User 看起来像

                  I am using Flask and SQLAlchemy and their Flask-SQLAlchemy extension. my model User looks like

                  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 看起来像

                  As described here, I modified env.py to look like

                  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() 方法

                  but file alembic/versions/55a9d5 has empty upgrade() and downgrade() methods

                  """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模型?请帮忙

                  How come it is not able to understand that there is a new User model? Please help

                  推荐答案

                  根据@zzzeek,在我的 env.py 中包含以下内容后,我能够使用 --autogenerate 选项

                  As per @zzzeek, after I included the following in my env.py, I was able to work with --autogenerate option

                  env.pyrun_migrations_online()

                  from configuration import app
                  from core.expense.models import user # added my model here
                  
                  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)
                  

                  然后我运行 alembic revision --autogenerate -m "Added initial table" 并得到了

                  then I ran alembic revision --autogenerate -m "Added initial table" and got

                  def upgrade():
                      ### commands auto generated by Alembic - please adjust! ###
                      op.create_table('users',
                      sa.Column('uuid', sa.GUID(), nullable=False),
                      sa.Column('email', sa.String(), nullable=False),
                      sa.Column('password', sa.String(), nullable=False),
                      sa.Column('created_on', sa.DateTime(timezone=True), nullable=True),
                      sa.Column('last_login', sa.DateTime(timezone=True), nullable=True),
                      sa.PrimaryKeyConstraint('uuid'),
                      sa.UniqueConstraint('email'),
                      sa.UniqueConstraint('uuid')
                      )
                      ### end Alembic commands ###
                  

                  感谢迈克尔的所有帮助!

                  Thank you Michael for all your help!

                  这篇关于Alembic --autogenerate 产生空迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                  Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                  Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                  How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                  Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                  Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)
                    <bdo id='elxK9'></bdo><ul id='elxK9'></ul>
                    <tfoot id='elxK9'></tfoot>
                      <tbody id='elxK9'></tbody>

                    <i id='elxK9'><tr id='elxK9'><dt id='elxK9'><q id='elxK9'><span id='elxK9'><b id='elxK9'><form id='elxK9'><ins id='elxK9'></ins><ul id='elxK9'></ul><sub id='elxK9'></sub></form><legend id='elxK9'></legend><bdo id='elxK9'><pre id='elxK9'><center id='elxK9'></center></pre></bdo></b><th id='elxK9'></th></span></q></dt></tr></i><div id='elxK9'><tfoot id='elxK9'></tfoot><dl id='elxK9'><fieldset id='elxK9'></fieldset></dl></div>

                  • <small id='elxK9'></small><noframes id='elxK9'>

                        <legend id='elxK9'><style id='elxK9'><dir id='elxK9'><q id='elxK9'></q></dir></style></legend>