CREATING DATABASE FILE IN FLASK
I'm a newbie in Python and Flask so I was following a tutorial on youtube https://youtu.be/2geC50roans?t=362. All was well until the point I needed to create a database file. My code didn't create a file as in the tutorial, however I'm not seeing where my code differs with that on the tutorial. I'm using python 3.8 and Pycharm on windows 10. I have also installed Flask, SQLite3, flask_sqlalchemy, sqlalchemy as required by the tutorial. My code is as follows;
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import Column, Integer, Text
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///pin.db'
db = SQLAlchemy(app)
class Pin(db.Model):
id = Column(Integer, primary_key=True)
title = Column(Text, unique=False)
image = Column(Text, unique=False)
db.create_all()
@app.route('/')
def index():
return "Hello World!"
app.debug = True
if __name__ == '__main__':
app.run()

The following is the error message:
"C:\Users\Takunda Mafuta\AppData\Local\Programs\Python\Python38-32\python.exe" "C:/Users/Takunda Mafuta/Videos/lgT Personal Development/Data Science/Python/Tutorials/JetBrainsTV/Excercise/pin_clone/pin_clone.py"
Traceback (most recent call last):
File "C:/Users/Takunda Mafuta/Videos/lgT Personal Development/Data Science/Python/Tutorials/JetBrainsTV/Excercise/pin_clone/pin_clone.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

Kindly assist. Thank you.
Please sign in to leave a comment.
Hello,
I am wondering if the code is executed out of PyCharm, in a system terminal, would you get the same error?
Please see https://intellij-support.jetbrains.com/hc/en-us/articles/360010202240 to activate the same venv in cmd.
this code is correct even I'm a newbie and I ran this code in pycharm myself it ran BUT you need to understand that the files you've been searching for could not be found same happened with me
Step 1 search the file name in windows search bar : example : pin.db
OR u need to upgrade pycharm or reaload it in your pc