Using the video as a reference, create the following code (app.py) in the web application development course for todolist using Python.
>>>from app import db
>>>db.create_all()
I would like to create a database by typing the command in , but no matter how many times I try, it doesn't work.(In the video, the content starts from the 18th minute)
Video for reference:
Python(Flask)×Web App Development Introductory Course (YouTube)
"Column", "Integer", "String", and "DateTime" on app.py shown below.
**Open Attribute Reference for Class 'SQLAlchemy' 'Column'**
I thought it might be because is a warning message.
editor:pycharm
interpreter: 3.8
OS:windows10
SQLAlchemy:1.3.20
I look forward to your kind cooperation.
app.py
from flash import Flask, render_template
from flash_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config ["SQLALCHEMY_DATABASE_URI"] = "sqlite://todo.db"
db = SQLAlchemy(app)
class Post (db.Model):
id=db.Column(db.Integer, primary_key=True)
title=db.Column(db.String(30), nullable=False)
detail = db.Column(db.String(100))
due=db.Column(db.DateTime, nullable=False)
@ app.route("/")
def index():
return render_template("index.html")
if__name__=="__main__":
app.run(debug=True)
I followed the following article in the comment, which is equivalent to the YouTube video in the question, and the steps described in the question (5-2 | Database Item Definition Terminal: Python Interactive Shell Database Creation) were successful.
[Save] Introduction to Flask in 30 minutes!Python engineer explains how to create a web app
The difference between the question and the environment will be as follows:
PyCharm:Not used
Number of Python editions: 3.10.2
OS: Same thing
SQLAlchemy:1.4.31
The only difference between app.py
is the difference between '
and "
.I tried to change it to the same source code as the question, but it also worked.
Below is a list of modules including others.
Package Version
---------------- -------
click 8.0.4
colorama 0.4.4
Flask 2.0.3
Flask - SQLAlchemy 2.5.1
greenlet 1.1.2
itsdangerous 2.1.0
Jinja 23.0.3
MarkupSafe 2.1.0
pip22.0.3
setupools 60.9.3
SQLAlchemy 1.4.31
Werkzeug 2.0.3
wheel 0.37.1
When importing db
from app.py
, the warning is as follows, which is different from the "concerns" of the question and the display in the introduction article.However, db.create_all()
is successful.
C:\Develop\Python\vFLSK\lib\site-packages\flask_sqlalchemy\_init__.py:872:FSADepreciationWarning:SQLALCHEMY_TRACK_MODIFICATIONS adds signature overhead and will be disabled by default in the future. Future. True.
warnings.warn (FSADeprecationWarning)
Other than that, whether or not you use PyCharm is the only one.
The difference in Python numbers is not particularly problematic considering the article's Python is 3.7.3.
In the work so far, it may be a misunderstanding that SQLAlchemy version may be lowered and reinstalled (sometimes it doesn't run higher than 1.3.20).
Why don't you try changing the SQLAlchemy
to the latest version?
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
578 Understanding How to Configure Google API Key
911 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.