使用web.py插入

时间:2013-05-22 06:29:18

标签: insert web.py psycopg2

我启动了一个名为GREEN.db的新数据库,其中一个TABLE定义如下:

CREATE TABLE articles(
                      "articleID" serial NOT NULL,

                      "articleTitle" character varying(21) NOT NULL,

                      "articleContent" text NOT NULL,

                      "articleAuthor" character varying(7) NOT NULL ,

                      "articleTime" timestamp without time zone DEFAULT now(),

                      CONSTRAINT articles_pkey PRIMARY KEY ("articleID")
                      )

我的代码编写如下:

db = web.database(dbn='postgres', db='green',user='YOng',password='xxx')

......

i = web.input()
t = time.localtime(time.time())
st = time.strftime("%Y-%m-%d %H:%M:%S", t)
datas = list(db.query("""SELECT * FROM articles ORDER BY "articleID" DESC"""))
    n = db.insert("articles",
    articleID=len(datas)+1, \
    articleTitle=i.post_title, \
    articleContent=i.post_content, \
    articleAuthor="YOng", \
    articleTime=st)
web.seeother('/')

错误抛出说:

  

psycopg2.ProgrammingError:关系“文章”的列“articleid”   不存在第1行:插入INTO文章(articleTitle,   articleAuthor,articleID ... ^

我不知道这段代码发生了什么。有没有人有任何建议?任何帮助表示赞赏〜

1 个答案:

答案 0 :(得分:1)

也许是因为大写字母?

错误是:

column "articleid" of relation "articles" does not exist

您的专栏名称是“articleID”