lgTakunda
lgTakunda

Reputation: 51

Creating database file in Python Flask

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

Upvotes: 0

Views: 630

Answers (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

Upvotes: 2

Related Questions