简体   繁体   English

sqlalchemy.exc.ProgrammingError:(psycopg2.ProgrammingError)关系“故事”不存在

[英]sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) relation “story” does not exist

So this is my code below. 这是下面的代码。 I'm trying to create a database, with one story table. 我正在尝试创建一个具有一个故事表的数据库。 The input comes from the html input part 输入来自html输入部分

from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from flask import request, redirect, url_for

app = Flask(__name__)
password = input("Your database password: ")
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://adambodnar:{}@localhost/user_stories'.format(password)
db = SQLAlchemy(app)

class Story(db.Model):
   id = db.Column(db.Integer, primary_key=True)
   story_title = db.Column(db.String(80), unique=True)
   user_story = db.Column(db.Text)
   acceptance_criteria = db.Column(db.Text)
   business_value = db.Column(db.Integer)
   estimation = db.Column(db.Integer)
   status = db.Column(db.String(30))

   def __init__(self, story_title, user_story, acceptance_criteria, business_value, estimation, status):
        self.story_title = story_title
        self.user_story = user_story
        self.acceptance_criteria = acceptance_criteria
        self.business_value = business_value
        self.estimation = estimation
        self.status = status


@app.route('/')
def index():
    return render_template('form.html')


@app.route('/story', methods=['POST'])
def story_post():
    new_story = Story(request.form['story_title'],request.form['user_story'], request.form['acceptance_criteria'], request.form['business_value'], request.form['estimation'], request.form['status'])


    db.session.add(new_story)
    db.session.commit()
    return redirect(url_for('index'))

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)

when I try to run this, I get the following error: 当我尝试运行此命令时,出现以下错误:

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) relation "story" does not exist
LINE 1: INSERT INTO story (story_title, user_story, acceptance_crite...
                ^
 [SQL: 'INSERT INTO story (story_title, user_story, acceptance_criteria, business_value, estimation, status) VALUES (%(story_title)s, %(user_story)s, %(acceptance_criteria)s, %(business_value)s, %(estimation)s, %(status)s) RETURNING story.id'] [parameters: {'acceptance_criteria': 'asdasd', 'estimation': '1', 'user_story': 'asd', 'status': 'Planning', 'story_title': 'asd', 'business_value': '100'}]

The story table is not even created, I checked it through pgAdmin. 故事表甚至没有创建,我通过pgAdmin检查了它。 I've tried a lot of things, some questions suggested to drop the table, but it's not created 我已经尝试了很多东西,建议删除表一些问题,但是它不是创建的

Have you followed the quickstart guide for Flask and sqlalchemy? 您是否遵循了Flask和sqlalchemy的快速入门指南 Anyway, on the guide you will notice that it says to do this: 无论如何,在指南上,您会注意到它说要这样做:

To create the initial database, just import the db object from an interactive Python shell and run the SQLAlchemy.create_all() method to create the tables and database: 要创建初始数据库,只需从交互式Python Shell中导入db对象,然后运行SQLAlchemy.create_all()方法即可创建表和数据库:

 >>> from yourapplication import db >>> db.create_all() 

In the code you included with your question the table creation code seems to be missing, which explains the table not being created. 在问题中包含的代码中,似乎缺少表创建代码,这说明未创建表。

You can consider including db.create_all() with your application (put it right after db = SqlAlchemy(app) ) - if this wrapper functions like the standard sqlalchemy version it should only create new tables and not blow up if tables already exist. 您可以考虑在应用程序中包括db.create_all() (在db = SqlAlchemy(app)之后放进去)-如果此包装器功能类似于标准sqlalchemy版本,则它仅应创建新表,并且如果表已存在则不会db = SqlAlchemy(app)

暂无
暂无

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

相关问题 Flask:sqlalchemy.exc.ProgrammingError:(psycopg2.ProgrammingError)关系“users”不存在 - Flask : sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) relation “users” does not exist sqlalchemy.exc.ProgrammingError:(psycopg2.ProgrammingError)语法错误在“:”或附近 - sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) syntax error at or near “:” sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) 关系“用户”不存在 - sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "users" does not exist psycopg2.ProgrammingError:关系“匹配”不存在 - psycopg2.ProgrammingError: relation “matches” does not exist sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) 无法适应类型 'Row' - sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'Row' sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) 无法适应类型“属性” - sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'property' sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) 无法适应“电影”类型 - sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'Movie' sqlalchemy.exc.ProgrammingError:(psycopg2.errors.UndefinedObject)编码“UTF8”的排序规则“utf8”不存在 - sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedObject) collation "utf8" for encoding "UTF8" does not exist (Flask)Heroku 错误:sqlalchemy.exc.ProgrammingError:(psycopg2.errors.DuplicateTable)关系“用户”已经存在 - (Flask) Heroku Error: sqlalchemy.exc.ProgrammingError: (psycopg2.errors.DuplicateTable) relation "user" already exists 烧瓶的sqlalchemy.exc.ProgrammingError - sqlalchemy.exc.ProgrammingError for flask
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM