peewee在这样的桌子上

时间:2016-11-12 02:02:46

标签: python postgresql flask peewee

当我使用peewee ORM时,我创建了一个postgresql数据库,我创建了3个脚本来创建表和addUser和dropTable,它运行良好,但是当我尝试查询表用户中的数据时,它会出现:表:用户 有一些我的代码: confiuration.py

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

    @staticmethod
    def init_app(app):
        pass

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

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

from playhouse.flask_utils import FlaskDB
from flask_login import LoginManager

lm = LoginManager()
db = FlaskDB()

和我的一个数据库脚本 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()

当我运行我的createTable.py它运行良好并且在我的数据库中显示3个表,并且在addUser之后我的User表中有正常数据。但是,当我尝试在User表中获取用户或在用户表中查询数据时,它会在这样的表格上反响我:用户"并且在我的工作目录中将出现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

这是一些截图

[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

似乎当我运行我的webapp时,我无法连接我的本地数据库。

1 个答案:

答案 0 :(得分:0)

如果您共享模型定义或完整回溯,请务必使用。老实说,你经历了这么多努力,但你忘了包含实际有用的信息。

首先,尝试在用户模型中将其重命名为"用户":

Running TestSuite
Nov 13, 2016 9:25:28 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: executable: /softwares/build.tool/.jenkins/jobs/SELENIUM_UI/workspace/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs
Nov 13, 2016 9:25:28 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: port: 19175
Nov 13, 2016 9:25:28 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: arguments: [--webdriver=19175, --webdriver-logfile=/softwares/build.tool/.jenkins/jobs/SELENIUM_UI/workspace/phantomjsdriver.log]
Nov 13, 2016 9:25:28 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: environment: {}
/softwares/build.tool/.jenkins/jobs/SELENIUM_UI/workspace/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs: /lib64/libz.so.1: no version information available (required by /softwares/build.tool/.jenkins/jobs/SELENIUM_UI/workspace/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs)
/softwares/build.tool/.jenkins/jobs/SELENIUM_UI/workspace/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /softwares/build.tool/.jenkins/jobs/SELENIUM_UI/workspace/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs)
/softwares/build.tool/.jenkins/jobs/SELENIUM_UI/workspace/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /softwares/build.tool/.jenkins/jobs/SELENIUM_UI/workspace/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs)
/softwares/build.tool/.jenkins/jobs/SELENIUM_UI/workspace/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs: /lib64/libc.so.6: version `GLIBC_2.9' not found (required by /softwares/build.tool/.jenkins/jobs/SELENIUM_UI/workspace/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs)
/softwares/build.tool/.jenkins/jobs/SELENIUM_UI/workspace/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs: /lib64/libc.so.6: version `GLIBC_2.10' not found (required by /softwares/build.tool/.jenkins/jobs/SELENIUM_UI/workspace/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs)
/softwares/build.tool/.jenkins/jobs/SELENIUM_UI/workspace/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs: /lib64/libc.so.6: version `GLIBC_2.7' not found (required by /softwares/build.tool/.jenkins/jobs/SELENIUM_UI/workspace/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs)
Nov 13, 2016 9:25:49 PM org.openqa.selenium.os.UnixProcess checkForError
SEVERE: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
Tests run: 7, Failures: 1, Errors: 0, Skipped: 6, Time elapsed: 22.943 sec <<< FAILURE! - in TestSuite
pageSetup(com.visualiq.automation.selfservice.ClientSetupTest)  Time elapsed: 22.748 sec  <<< FAILURE!
org.openqa.selenium.WebDriverException: 
Timed out waiting for driver server to start.
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
System info: host: 'hnet11234.inetservices.com', ip: '10.300.14.86', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.18-371.1.2.el5', java.version: '1.8.0_101'
Driver info: driver.version: PhantomJSDriver