Hey i am making a social media app and want to save a post to my db. but i keep get getting the error












-1















sqlalchemy.exc.OperationalError
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: blogpost [SQL: 'INSERT INTO blogpost (title, author, date_posted, content) VALUES (?, ?, ?, ?)'] [parameters: ('qedqdq', 'qwdqdwd', '2018-12-31 22:51:35.669388', 'qwdqwdqwdqwdqwdqwdqwdqwdw')] (Background on this error at: http://sqlalche.me/e/e3q8)



After i send the post to get published in my database i get ^^ the error



here are some of the code i am using.



Any help would be great thanks!!!



app.py



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

app = Flask(__name__)

app.config['SQLALCHEMY_DATABASE_URL'] = 'sqlite:///Users/------/Desktop/face0/face/blog.db'

db = SQLAlchemy(app)

class Blogpost(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(50))
author = db.Column(db.String(20))
date_posted = db.Column(db.DateTime)
content = db.Column(db.Text)

@app.route('/addpost', methods=['POST'])
def addpost():
title = request.form['title']
author = request.form['author']
content = request.form['content']

post = Blogpost(title=title, author=author, content=content, date_posted=datetime.now())

db.session.add(post)
db.session.commit()

return redirect(url_for('index'))









share|improve this question



























    -1















    sqlalchemy.exc.OperationalError
    sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: blogpost [SQL: 'INSERT INTO blogpost (title, author, date_posted, content) VALUES (?, ?, ?, ?)'] [parameters: ('qedqdq', 'qwdqdwd', '2018-12-31 22:51:35.669388', 'qwdqwdqwdqwdqwdqwdqwdqwdw')] (Background on this error at: http://sqlalche.me/e/e3q8)



    After i send the post to get published in my database i get ^^ the error



    here are some of the code i am using.



    Any help would be great thanks!!!



    app.py



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

    app = Flask(__name__)

    app.config['SQLALCHEMY_DATABASE_URL'] = 'sqlite:///Users/------/Desktop/face0/face/blog.db'

    db = SQLAlchemy(app)

    class Blogpost(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50))
    author = db.Column(db.String(20))
    date_posted = db.Column(db.DateTime)
    content = db.Column(db.Text)

    @app.route('/addpost', methods=['POST'])
    def addpost():
    title = request.form['title']
    author = request.form['author']
    content = request.form['content']

    post = Blogpost(title=title, author=author, content=content, date_posted=datetime.now())

    db.session.add(post)
    db.session.commit()

    return redirect(url_for('index'))









    share|improve this question

























      -1












      -1








      -1








      sqlalchemy.exc.OperationalError
      sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: blogpost [SQL: 'INSERT INTO blogpost (title, author, date_posted, content) VALUES (?, ?, ?, ?)'] [parameters: ('qedqdq', 'qwdqdwd', '2018-12-31 22:51:35.669388', 'qwdqwdqwdqwdqwdqwdqwdqwdw')] (Background on this error at: http://sqlalche.me/e/e3q8)



      After i send the post to get published in my database i get ^^ the error



      here are some of the code i am using.



      Any help would be great thanks!!!



      app.py



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

      app = Flask(__name__)

      app.config['SQLALCHEMY_DATABASE_URL'] = 'sqlite:///Users/------/Desktop/face0/face/blog.db'

      db = SQLAlchemy(app)

      class Blogpost(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      title = db.Column(db.String(50))
      author = db.Column(db.String(20))
      date_posted = db.Column(db.DateTime)
      content = db.Column(db.Text)

      @app.route('/addpost', methods=['POST'])
      def addpost():
      title = request.form['title']
      author = request.form['author']
      content = request.form['content']

      post = Blogpost(title=title, author=author, content=content, date_posted=datetime.now())

      db.session.add(post)
      db.session.commit()

      return redirect(url_for('index'))









      share|improve this question














      sqlalchemy.exc.OperationalError
      sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: blogpost [SQL: 'INSERT INTO blogpost (title, author, date_posted, content) VALUES (?, ?, ?, ?)'] [parameters: ('qedqdq', 'qwdqdwd', '2018-12-31 22:51:35.669388', 'qwdqwdqwdqwdqwdqwdqwdqwdw')] (Background on this error at: http://sqlalche.me/e/e3q8)



      After i send the post to get published in my database i get ^^ the error



      here are some of the code i am using.



      Any help would be great thanks!!!



      app.py



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

      app = Flask(__name__)

      app.config['SQLALCHEMY_DATABASE_URL'] = 'sqlite:///Users/------/Desktop/face0/face/blog.db'

      db = SQLAlchemy(app)

      class Blogpost(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      title = db.Column(db.String(50))
      author = db.Column(db.String(20))
      date_posted = db.Column(db.DateTime)
      content = db.Column(db.Text)

      @app.route('/addpost', methods=['POST'])
      def addpost():
      title = request.form['title']
      author = request.form['author']
      content = request.form['content']

      post = Blogpost(title=title, author=author, content=content, date_posted=datetime.now())

      db.session.add(post)
      db.session.commit()

      return redirect(url_for('index'))






      python database flask sqlalchemy






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 1 at 4:00









      shortenshorten

      32




      32
























          1 Answer
          1






          active

          oldest

          votes


















          0














          As mentioned in the flask-sqlalchemy documentation, you will need to first create the database by calling the create_all function.




          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:




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


          In your case this may look something like the following:



          $ python
          >>> from app import db
          >>> db.create_all()
          >>> exit()





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992923%2fhey-i-am-making-a-social-media-app-and-want-to-save-a-post-to-my-db-but-i-keep%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            As mentioned in the flask-sqlalchemy documentation, you will need to first create the database by calling the create_all function.




            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:




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


            In your case this may look something like the following:



            $ python
            >>> from app import db
            >>> db.create_all()
            >>> exit()





            share|improve this answer




























              0














              As mentioned in the flask-sqlalchemy documentation, you will need to first create the database by calling the create_all function.




              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:




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


              In your case this may look something like the following:



              $ python
              >>> from app import db
              >>> db.create_all()
              >>> exit()





              share|improve this answer


























                0












                0








                0







                As mentioned in the flask-sqlalchemy documentation, you will need to first create the database by calling the create_all function.




                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:




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


                In your case this may look something like the following:



                $ python
                >>> from app import db
                >>> db.create_all()
                >>> exit()





                share|improve this answer













                As mentioned in the flask-sqlalchemy documentation, you will need to first create the database by calling the create_all function.




                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:




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


                In your case this may look something like the following:



                $ python
                >>> from app import db
                >>> db.create_all()
                >>> exit()






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 1 at 5:23









                MarcusMarcus

                1,326913




                1,326913
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992923%2fhey-i-am-making-a-social-media-app-and-want-to-save-a-post-to-my-db-but-i-keep%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas