Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python heroku上的Peewee和postgres,无法创建表_Python_Postgresql_Python 3.x_Heroku_Peewee - Fatal编程技术网

Python heroku上的Peewee和postgres,无法创建表

Python heroku上的Peewee和postgres,无法创建表,python,postgresql,python-3.x,heroku,peewee,Python,Postgresql,Python 3.x,Heroku,Peewee,我尝试在没有数据库的情况下使用我的应用程序,但使用peewee和postgres,它根本无法创建表 我在网上尝试了不同的方法,但不起作用,如果你在heroku上使用过peewee,请帮助 我的模特 if os.environ.get('DATABASE_URL'): DATABASE_URL = os.environ.get('DATABASE_URL') db = urlparse(DATABASE_URL) user = db.username passwo

我尝试在没有数据库的情况下使用我的应用程序,但使用peewee和postgres,它根本无法创建表

我在网上尝试了不同的方法,但不起作用,如果你在heroku上使用过peewee,请帮助

我的模特

if os.environ.get('DATABASE_URL'):
    DATABASE_URL = os.environ.get('DATABASE_URL')
    db = urlparse(DATABASE_URL)
    user = db.username
    password = db.password
    path = db.path[1:]
    host = db.hostname
    port = db.port
    database = PostgresqlDatabase(path, user=user, password=password, host=host, port=port)
else:
    database = PostgresqlDatabase('heroku')


class BaseModel(Model):
    class Meta:
        database = database


class User(BaseModel):
    name = CharField()
    email = CharField(null=False, unique=True)
将CREATETABLE从if语句移动到欢迎函数表后,将创建该表

@app.route('/')
def welcome():
    call('printenv')
    a = 'Default'
    b = 'Default'
    if os.environ.get('DATABASE_URL'):
        a = os.environ.get('DATABASE_URL')
    if os.environ.get('HEROKU'):
        b = os.environ.get('HEROKU')
    create_model_tables([Users], fail_silently=True)
    Users.insert(name='John', email='Doe').execute()
    return render_template('index.html', a=a, b=b)


if __name__ == '__main__':
    app.run(port=5000, debug=True)
“用户”是保留表--请尝试:

使用这种方法,它很容易,而且出错的可能性很小

并且您必须在
之前创建表,如果uuuu name_uuuu=='\uuuuu main:
,则此语句,因为在heroku上,您提供的设置使其下的任何内容都无法工作

像我的
uswgi.ini

[uwsgi]
http-socket = :$(PORT)
master = true
die-on-term = true
module = app:app
memory-report = true

module=app:app
表示从app.py运行应用程序而不是运行app.py

我已更改了表名,但仍然收到相同的错误。第1行:插入“用户”(“名称”、“电子邮件”)值('John'、'Doe')。。。2017-04-20T03:36:57.055897+00:00应用程序[web.1]:^2017-04-20T03:36:57.055896+00:00应用程序[web.1]:psycopg2.ProgrammingError:关系“用户”不存在显然,您需要创建表。
from playhouse.db_url import connect
import settings

local_url = 'postgresql://{}:{}@localhost:5432/{}'.format(settings.DB_USER, settings.DB_PASS, settings.DB_NAME)

database = connect(os.environ.get('DATABASE_URL') or local_url)


class BaseModel(Model):
    class Meta:
        database = database
[uwsgi]
http-socket = :$(PORT)
master = true
die-on-term = true
module = app:app
memory-report = true