您好老师 我在9-6这一节使用__abstract__ = True 使Base类不生成表,之后我运行代码后连接数据库并没有发现新增status字段
来源:9-6 用户注册
宝迪
2018-06-18
Base 类
class Base(db.Model): __abstract__ = True # create_time = Column('create_time', Integer) status = Column(SmallInteger, default=1)
Book类
class Book(db.Model): id = Column(Integer, primary_key=True, autoincrement=True) title = Column(String(50), nullable = False) author = Column(String(30), default='未名') binding = Column(String(20)) publisher = Column(String(50)) price = Column(String(20)) pages = Column(String(20)) pubdate = Column(String(20)) isbn = Column(String(15),nullable=False, unique=True) summary = Column(String(1000)) image = Column(String(50))
Gift 类
class Gift(Base): id = Column(Integer, primary_key=True) user = relationship('User') uid = Column(Integer, ForeignKey('user.id')) isbn = Column(String(15), nullable=False) # book = relationship('Book') 没有保存书籍的数据 # bid = Column(Integer, ForeignKey('book.id')) launched = Column(Boolean, default=False)
User类
class User(Base): id = Column(Integer, primary_key=True) nickname = Column(String(24), nullable=False) phone_number = Column(String(18), unique=True) email = Column(String(50), nullable=False) confirmed = Column(Boolean, default=0) beans = Column(Float, default=0) send_counter = Column(Integer, default=0) receive_counter = Column(Integer, default=0) wx_open_id = Column(String(50)) wx_name = Column(String(32))
配置文件
DEBUG = True SQLALCHEMY_DATABASE_URI = 'mysql+cymysql://root:1155665a@localhost:3306/fisher' SECRET_KEY = 'ASDASDASDJASKLJBLCBHIURORGTBN3432489233*&9W793*(' SQLALCHEMY_TRACK_MODIFICATIONS = True
运行日志
C:\Users\dell\.virtualenvs\flask-y8ELlMjF\Scripts\python.exe E:/onedrive/生活/文档/flask/run.py
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Restarting with stat
* Debugger is active!
* Debugger PIN: 120-391-608
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
数据库截图
写回答
3回答
-
数据迁移,或者自己手段 加这个字段。
112018-06-18 -
慕侠8395484
2019-04-09
应该怎么做才能生成三张表
00 -
宝迪
提问者
2018-06-18
老师 我删除了 原有的表 status字段出现了 有没有 什么办法不需要删除原有的表
00
相似问题