Search code examples
pythonpostgresqlsqlalchemypyramid

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.

I'm using sqlalchemy to interact with a postgresql db in a pyramid (python) framework (OS Ubuntu).

My schema is described in a models.py file.

I'm trying to insert the record in my 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.


Solution

  • 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. 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.