这是我的代码:
from example1 import db, Puppy
db.create_all()
sam = Puppy('Sammy', 3)
frank = Puppy ('Frankie',2)
print (sam.id)
print (frank.id)
db.session.add_all([sam,frank])
db.session.commit()
print(sam.id)
print(frank.id)
这是我的错误:
& C:/Python/Python38/python.exe r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py
Traceback (most recent call last):
File "r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py", line 1, in <module>
from example1 import db, Puppy
File "r:\dinabelajar\Flask-Bootcamp-master\05-Databases\coba\example1.py", line 3, in <module>
from flask_sqlalchemy import SQLAlchemy
File "C:\Python\Python38\lib\site-packages\flask_sqlalchemy\__init__.py", line 22, in <module>
import sqlalchemy
File "C:\Python\Python38\lib\site-packages\sqlalchemy\__init__.py", line 9, in <module>
from .sql import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\__init__.py", line 8, in <module>
from .expression import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\expression.py", line 34, in <module>
from .visitors import Visitable
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\visitors.py", line 28, in <module>
from .. import util
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\__init__.py", line 8, in <module>
from .compat import callable, cmp, reduce, \
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\compat.py", line 172, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
PS R:\dinabelajar\Flask-Bootcamp-master> & C:/Python/Python38/python.exe r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py
Traceback (most recent call last):
File "r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py", line 1, in <module>
from example1 import db, Puppy
File "r:\dinabelajar\Flask-Bootcamp-master\05-Databases\coba\example1.py", line 3, in <module>
from flask_sqlalchemy import SQLAlchemy
File "C:\Python\Python38\lib\site-packages\flask_sqlalchemy\__init__.py", line 22, in <module>
import sqlalchemy
File "C:\Python\Python38\lib\site-packages\sqlalchemy\__init__.py", line 9, in <module>
from .sql import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\__init__.py", line 8, in <module>
from .expression import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\expression.py", line 34, in <module>
from .visitors import Visitable
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\visitors.py", line 28, in <module>
from .. import util
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\__init__.py", line 8, in <module>
from .compat import callable, cmp, reduce, \
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\compat.py", line 172, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
PS R:\dinabelajar\Flask-Bootcamp-master> & C:/Python/Python38/python.exe r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py
Traceback (most recent call last):
File "r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py", line 1, in <module>
from example1 import db, Puppy
File "r:\dinabelajar\Flask-Bootcamp-master\05-Databases\coba\example1.py", line 3, in <module>
from flask_sqlalchemy import SQLAlchemy
File "C:\Python\Python38\lib\site-packages\flask_sqlalchemy\__init__.py", line 22, in <module>
import sqlalchemy
File "C:\Python\Python38\lib\site-packages\sqlalchemy\__init__.py", line 9, in <module>
from .sql import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\__init__.py", line 8, in <module>
from .expression import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\expression.py", line 34, in <module>
from .visitors import Visitable
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\visitors.py", line 28, in <module>
from .. import util
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\__init__.py", line 8, in <module>
from .compat import callable, cmp, reduce, \
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\compat.py", line 172, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
PS R:\dinabelajar\Flask-Bootcamp-master> & C:/Python/Python38/python.exe r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py
Traceback (most recent call last):
File "r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py", line 1, in <module>
from example1 import db, Puppy
File "r:\dinabelajar\Flask-Bootcamp-master\05-Databases\coba\example1.py", line 3, in <module>
from flask_sqlalchemy import SQLAlchemy
File "C:\Python\Python38\lib\site-packages\flask_sqlalchemy\__init__.py", line 22, in <module>
import sqlalchemy
File "C:\Python\Python38\lib\site-packages\sqlalchemy\__init__.py", line 9, in <module>
from .sql import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\__init__.py", line 8, in <module>
from .expression import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\expression.py", line 34, in <module>
from .visitors import Visitable
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\visitors.py", line 28, in <module>
from .. import util
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\__init__.py", line 8, in <module>
from .compat import callable, cmp, reduce, \
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\compat.py", line 172, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
我该如何解决?
答案 0 :(得分:0)
您必须更新SQLAlchemy
pip uninstall SQLAlchemy
pip install SQLAlchemy==1.3.6