Flask正在尝试在数据库中添加ID字段,该字段每增加一次

2024-09-26 04:54:36 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码型号.py文件。在我尝试为“ID”添加一个新字段之前,一切都正常工作,该字段会随着每个项而递增。这是一个在googleappengine上运行的flask应用程序。你知道吗

from google.appengine.ext import db

class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.StringProperty(required = True)
    content = db.TextProperty(required = True)

这是我得到的回溯:

<type 'exceptions.AttributeError'>: 'module' object has no attribute 'Column'
Traceback (most recent call last):
  File "/base/data/home/apps/s~smart-cove-95709/1.384688470778541604/main.py", line 2, in <module>
    from blog import app
  File "/base/data/home/apps/s~smart-cove-95709/1.384688470778541604/blog/__init__.py", line 7, in <module>
    import views
  File "/base/data/home/apps/s~smart-cove-95709/1.384688470778541604/blog/views.py", line 2, in <module>
    from models import Post
  File "/base/data/home/apps/s~smart-cove-95709/1.384688470778541604/blog/models.py", line 3, in <module>
    class Post(db.Model):
  File "/base/data/home/apps/s~smart-cove-95709/1.384688470778541604/blog/models.py", line 4, in Post
    id = db.Column(db.Integer, primary_key=True)

我也尝试过,但没有成功:

class Post(db.Model):
    id = db.Integer(primary_key=True)
    title = db.StringProperty(required = True)
    content = db.TextProperty(required = True)

Tags: appsinpytruehomedbdatabase