[英]peewee on such table
當我使用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
# -*- 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表中包含正常數據。 但是,當我嘗試在用戶表中獲取用戶或在用戶表中查詢數據時,它“在這樣的表上:用戶”對我產生了響應,並且在我的工作目錄中將出現一個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時,似乎無法連接本地數據庫。
如果您共享模型定義或完整的回溯,將對您有所幫助。 老實說,您付出了很多努力,但忘記了包含實際有用的信息。
首先,嘗試在您的用戶模型中將其重命名為“用戶”:
class User(db.Model):
username = CharField()
# etc, other fields
class Meta:
db_table = 'users'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.