简体   繁体   English

金字塔框架中Postgresql串行主键的sqlalchemy参数

[英]sqlalchemy argument for postgresql serial primary key in pyramid framework

I have found related questions but can't adapt them to my situation. 我发现了相关问题,但无法使其适应我的情况。 Here and the postgresql docs here . 这里和PostgreSQL文档这里

I'm using sqlalchemy to interact with a postgresql db in a pyramid (python) framework (OS Ubuntu). 我正在使用sqlalchemy与金字塔(python)框架(OS Ubuntu)中的postgresql数据库进行交互。

My schema is described in a models.py file. 我的模式在models.py文件中描述。

I'm trying to insert the record in my views.py : 我正在尝试在我的views.py插入记录:

cam_event = Event(key,'fileprefix',now,'CAM',outfile,
                  'new fake project','new fake memo')

where I would like to submit a null, none, or leave the position empty ('key' position in the line above) in my add command so that posgresql will fill it in. When I do any of those I get a "Programming Error" from one of the pyramid backend bits. 我想在其中添加null,不输入任何内容,或在我的add命令中将位置保留为空(上一行中的“键”位置),以便posgresql填充它。当我执行任何这些操作时,都会收到“编程错误”来自金字塔后端位之一。

Got it. 得到它了。 I had tried not specifying the primary_key column in my object creation, but that didn't work with an existing database with non-sequential numbers already in the table from earlier work. 我曾尝试在对象创建过程中未指定primary_key列,但这不适用于早期工作中表中已有非序号的现有数据库。 I dropped the table and let sqlalchemy create it fresh and never provided values for the primary_key field, just specified the sequence and let postgresql deal with the numbering. 我删除了表,让sqlalchemy为其创建新表,并且从未为primary_key字段提供任何值,仅指定了序列并让postgresql处理编号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM