python - 如何在 Heroku 服务器中创建在 sqlalchemy 模式中定义的表?

标签 python heroku sqlalchemy database-schema turbogears2

我正在使用 Python、SQLAlchemy、PostgreSQL 和 Turbogears 2.3 构建一个非常简单的应用程序。

该应用程序在我使用 SQLite 的本地计算机上运行。但是,当我将其上传到 Heroku 时,我不知道如何在那里创建 TurboGears2 用于身份验证和验证的 PostgreSQL 表:诸如 User、Gruoups、Permissions 之类的表。

我看到架构是在名为 auth.py 的文件中定义的,如下所示:

....
from sqlalchemy import Table, ForeignKey, Column
from sqlalchemy.types import Unicode, Integer, DateTime
from sqlalchemy.orm import relation, synonym

from example2.model import DeclarativeBase, metadata, DBSession

class User(DeclarativeBase):

    __tablename__ = 'tg_user'

    user_id = Column(Integer, autoincrement=True, primary_key=True)
    user_name = Column(Unicode(16), unique=True, nullable=False)
    email_address = Column(Unicode(255), unique=True, nullable=False)
    display_name = Column(Unicode(255))
    _password = Column('password', Unicode(128))
    created = Column(DateTime, default=datetime.now)

    def __repr__(self):
        return '<User: name=%s, email=%s, display=%s>' % (
            repr(self.user_name), repr(self.email_address), repr(self.display_name))

    def __unicode__(self):
        return self.display_name or self.user_name
...

所以我的问题是如何在 Heroku 服务器中自动创建这些表?我必须执行什么命令或脚本?

编辑:感谢 JPub 的回答,我阅读了文档,了解如何从控制台执行此操作:

$ gearbox setup-app -c production.ini

要在 Heroku 中执行此操作,应该是:

$ heroku run 'gearbox setup-app -c production.ini'

最佳答案

我没有任何 Turbogears 方​​面的经验,但阅读文档后您有两个选择。

直接创建:

http://turbogears.readthedocs.org/en/latest/turbogears/gearbox.html#setup-app

编写自己的迁移:

http://turbogears.readthedocs.org/en/latest/turbogears/migrations.html

关于python - 如何在 Heroku 服务器中创建在 sqlalchemy 模式中定义的表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20013477/

相关文章:

java - 我应该如何修复这个由于在 Heroku 上运行而导致的 Java 错误?

python - 如何为 Linux 和 Windows 分发带有嵌入式 Firebird SQL 的 Python 程序

python - 将 Tensorflow 分析器与 tf.Estimator 结合使用

python - OpenCV python inRange 方法导致 C++ 模块出错

python - 从 Python 中的 float 中获取日期时间

python - Flask-SQLAlchemy 无法在线程中更新数据

postgresql - 将 postgresql 模式传递给 alembic 迁移

python - ._GLOBAL_DEFAULT_TIMEOUT 发生在简单的 urlopen 上

heroku - 白色导航栏,Bootstrap 中的放置问题

facebook - Webhooks 失败并显示 "Invalid Scopes: pages_messaging_subscriptions"