I'm a beginner in Python. I'm using Pycharm and Flask to create a web app. I have written the following code but its giving me an error. Kindly assist I want to create a database.
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
db = SQLAlchemy(app)
class Todo(db.Model):
id = db.Column(db.Interger, primary_key=True)
content = db.Column(db.String(200), nullable=False)
completed = db.Colmnn(db.Interger, default=0)
date_created = db.Column(db.DateTime, default=datetime.utcnow)
def __repr__(self):
return '<Task %r>' % self.id
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
'''
Error:
"C:\Users\Takunda Mafuta\AppData\Local\Programs\Python\Python38-32\python.exe" "C:/Users/Takunda Mafuta/Videos/lgT Personal Development/Data Science/Python/Tutorials/FreeCodeCamp/Exercise/TaskMaster.py"
Traceback (most recent call last):
File "C:/Users/Takunda Mafuta/Videos/lgT Personal Development/Data Science/Python/Tutorials/FreeCodeCamp/Exercise/TaskMaster.py", line 2, in <module>
from flask_sqlalchemy import SQLAlchemy
File "C:\Users\Takunda Mafuta\AppData\Local\Programs\Python\Python38-32\lib\site-packages\flask_sqlalchemy\__init__.py", line 13, in <module>
import sqlalchemy
File "C:\Users\Takunda Mafuta\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\__init__.py", line 8, in <module>
from . import util as _util # noqa
File "C:\Users\Takunda Mafuta\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\util\__init__.py", line 14, in <module>
from ._collections import coerce_generator_arg # noqa
File "C:\Users\Takunda Mafuta\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\util\_collections.py", line 16, in <module>
from .compat import binary_types
File "C:\Users\Takunda Mafuta\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\util\compat.py", line 264, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
Process finished with exit code 1
1 Answer 1
If you are using python 3.8, then time.clock() is :
Deprecated since version 3.3, will be removed in version 3.8: The behaviour of this function depends on the platform: use perf_counter() or process_time() instead, depending on your requirements, to have a well defined behaviour.
Please read the document here.
Also Update sqlalchemy to v1.3.6 for Windows + Py3.8 fixes.. Read it here : https://github.com/sqlalchemy/sqlalchemy/issues/4731
-
I didn't get it neither in the document. Where exactly was I using time.clock() that I need to change to perf_counter() or process_time(). Pardon me for my ignorance, I am a newbie in programming.lgTakunda– lgTakunda2020年02月03日 10:11:21 +00:00Commented Feb 3, 2020 at 10:11
-
what is your sqlalchemy version...?? If you are on the latest version of python, make sure to get the latest version of sqlalchemy.Shivendra Pratap Kushwaha– Shivendra Pratap Kushwaha2020年02月03日 11:50:58 +00:00Commented Feb 3, 2020 at 11:50
-
SQLAlchemy 1.2.17 and flask_sqlalchemy 2.4.1lgTakunda– lgTakunda2020年02月03日 14:35:46 +00:00Commented Feb 3, 2020 at 14:35
-
Update sqlalchemy to v1.3.6 for Windows + Py3.8 fixes.. This is that this document says. Read it here : github.com/sqlalchemy/sqlalchemy/issues/4731Shivendra Pratap Kushwaha– Shivendra Pratap Kushwaha2020年02月04日 07:15:35 +00:00Commented Feb 4, 2020 at 7:15
time.py
?