I have a Model with an auto-incrementing primary key. I want to be able to create an object from that model without an id, throw it away, and not have that Column's id auto-increment. Is that possible?
Assigning MyModel(id=None)
does not do that.
Assigning MyModel(id=0)
does not work either. It results in a Key (id)=(0) already exists.
response.
To clarify: I want to keep the Column as auto-incrementing, but disable that behavior in specific circumstances.
The goal is to have a MyModel
instance not saved in the database which I can pass to the template and can treat just like any other. For example, I want to print myModel.attribute
in a template, but without saving myModel
or incrememting the Column's id
counter.
This is Postgres/Python/Flask/SQLAlchemy.