greyli / helloflask

Hello, Flask!
https://docs.helloflask.com
MIT License
1.87k stars 2.53k forks source link

P146页在flask shell中查看模型对应的SQL模式 #137

Closed WhyTimePass closed 5 years ago

WhyTimePass commented 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
WhyTimePass commented 5 years ago

第一行代码<<<from app import db 改为 <<< from app import *; 即可运行;

greyli commented 5 years ago

书里没有导入 Note 类,在第一行加一个导入语句即可:

from app import Note