繁体   English   中英

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

[英]How to create table defined in sqlalchemy schema in the Heroku server?

我有一个使用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'

我对涡轮齿轮没有任何经验,但是通读文档有两种选择。

直接创建:

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

编写自己的迁移:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM