0

I am just trying to create a simple database, add a word, print it, then drop it, but I am getting an error message that I can't make any sense out of.

Error message:

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) table post has no column named word
[SQL: INSERT INTO post (word) VALUES (?)]
[parameters: ('Cheese 0',)]
(Background on this error at: http://sqlalche.me/e/13/e3q8)
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
db = SQLAlchemy(app)


class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    word = db.Column(db.String(10))


def create_db():
    db.create_all()

    for x in range(5):
        p = Post(word='Cheese ' + str(x))
        db.session.add(p)
        db.session.commit()

The provided link. I am new to Flask and SQLalchemy; I can't quite make out what the information is trying to say to me.

1
  • Complete the create_all() with a commit and without creating objects. Commented Nov 27, 2020 at 21:47

1 Answer 1

1

You missed db.session.commit()

def create_db():
    db.create_all()
    db.session.commit()

    for x in range(5):
        p = Post(word= f'Cheese {x}')
        db.session.add(p)
        db.session.commit()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.