简体   繁体   English

在这样的桌子上的小矮人

[英]peewee on such table

when I was useing peewee ORM, I created a postgresql database, and I made 3 script to createTable and addUser and dropTable, and it work well, but when I try to query the data in Table user, it appear: on such table : user there are some of my code: confiuration.py 当我使用peewee ORM时,我创建了一个postgresql数据库,并制作了3个脚本来创建createTable以及addUser和dropTable,它运行良好,但是当我尝试查询Table user中的数据时,它会出现:在这样的table上:user我的一些代码是:confiuration.py

class Configuration(object):
    DATABASE = 'postgresql://lc:********@localhost:5432/wolfsly'

    @staticmethod
    def init_app(app):
        pass

app.py app.py

# -*- coding: utf-8 -*-

from flask import Flask
from .extensions import db, lm
from .configuration import config

_all_ = ['create_app']

def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])

    config_blueprint(app)
    configure_template_filters(app)
    config_extensions(app)

    return app

def config_extensions(app):
    db.init_app(app)

extensions.py extensions.py

# -*- coding: utf-8 -*-

from playhouse.flask_utils import FlaskDB
from flask_login import LoginManager

lm = LoginManager()
db = FlaskDB()

and one of my database script createTable.py 和我的数据库脚本之一createTable.py

# -*- coding: utf-8 -*-

from application import create_app
from application.extensions import db


def createTables():
    app = create_app('default')
    from application.models import (User, Project, Photo)
    database = db.database
    database.connect()
    database.create_tables([User, Project, Photo])
    database.close()

if __name__ == '__main__':
    createTables()

when I run my createTable.py it work well and in my database appear 3 tables, and after addUser there is normal data in my User table. 当我运行createTable.py时,它运行良好,并且在数据库中显示了3个表,在addUser之后,User表中包含正常数据。 But when I try to get user in User table or query data in User Table it respone me "on such table: user"and in my work dir will appear a peewee.db here is some code in my auth/views.py 但是,当我尝试在用户表中获取用户或在用户表中查询数据时,它“在这样的表上:用户”对我产生了响应,并且在我的工作目录中将出现一个peewee.db,这是我的auth / views.py中的一些代码

# -*- coding: utf-8 -*-

from flask import render_template, redirect, url_for, flash
from flask_login import  current_user, login_user
from ..models import User
from . import bpAuth

@bpAuth.route('/login')
def login():
    pass

@bpAuth.route('/test')
def test():
    query = User.select(User.id, User.chinesename)
    print 'test'
    names = [user.chinesename for user in query]
    for user in query:
        print user.chinesename
    u = User.get(User.username == 'lc')
    print u.chinesename
    return u.chinesename

and here is some screenshot 这是一些截图

[enter image description here][1]
[enter image description here][2]
[enter image description here][3]


  [1]: https://i.stack.imgur.com/tWLYo.jpg
  [2]: https://i.stack.imgur.com/ldBRV.jpg
  [3]: https://i.stack.imgur.com/f0Tb7.jpg

and it seems when I run my webapp I can't connect my local database. 当我运行Webapp时,似乎无法连接本地数据库。

Be helpful if you shared your model definitions or the full traceback. 如果您共享模型定义或完整的回溯,将对您有所帮助。 Honestly you went through so much effort but you forgot to include the actually useful information. 老实说,您付出了很多努力,但忘记了包含实际有用的信息。

For one, try in your User model to rename it to "users": 首先,尝试在您的用户模型中将其重命名为“用户”:

class User(db.Model):
    username = CharField()
    # etc, other fields
    class Meta:
        db_table = 'users'

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

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