Closed WhyTimePass closed 5 years ago
CREATE TABLE note ( id INTEGER NOT NULL, body TEXT, PRIMARY KEY (id) )
>>>from app import db >>>db.create_all() >>>from sqlalchemy.shcema import CreateTable >>>print(CreateTable(Note.__table__) ### 实际情况 print(CreateTable(Note.__table__)) Traceback (most recent call last): File "<console>", line 1, in <module> NameError: name 'Note' is not defined ### 环境 * Python版本:3.6.8 * Flask版本:1.0.2 * 操作系统:win10
第一行代码<<<from app import db 改为 <<< from app import *; 即可运行;
书里没有导入 Note 类,在第一行加一个导入语句即可:
from app import Note
期望的行为
CREATE TABLE note ( id INTEGER NOT NULL, body TEXT, PRIMARY KEY (id) )