Hey i am making a social media app and want to save a post to my db. but i keep get getting the error
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
add a comment |
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
add a comment |
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
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
python database flask sqlalchemy
asked Jan 1 at 4:00
shortenshorten
32
32
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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()
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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()
add a comment |
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()
add a comment |
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()
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()
answered Jan 1 at 5:23
MarcusMarcus
1,326913
1,326913
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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