Ive run the postgres unit tests with every commit, which do a whole lot of
inserts. Postgres should be explicitly running the sequence corresponding
to the "id" column every time, despite the existince of the SERIAL. What
happens if you just say:
attribute_type.insert().execute(name='john', alias='jonathan')
?
dmiller wrote:
> Previously (I believe with r879) I was able to insert new items into
> my tables without having a "Sequence" defined. Now (using r893) I get
> an error.
>
> This is the table definition and object:
>
> CREATE TABLE attribute_type (
> id serial PRIMARY KEY,
> name varchar NOT NULL UNIQUE,
> alias varchar,
> UNIQUE (alias)
> ) WITHOUT OIDS;
>
> attributeType = sa.Table("attribute_type", engine,
> sa.Column("id", sa.Integer, primary_key=True),
> sa.Column("name", String, nullable=False, ),
> sa.Column("alias", String, nullable=False, ),
> )
>
> This is the code to reproduce the error:
>
> >>> AttributeType(name="Box Wood", alias="boxWood")
> >>> objectstore.commit()
> INSERT INTO attribute_type (id, name, alias) VALUES (%(id)s, %(name)
> s, %(alias)s)
> {'alias': 'boxWood', 'id': None, 'name': 'Box Wood'}
> Traceback (most recent call last):
> ...
> File "/Library/Python/2.3/site-packages/SQLAlchemy-0.91alpha-
> py2.3.egg/sqlalchemy/mapping/objectstore.py", line 69, in commit
> uow().commit(*obj)
> File "/Library/Python/2.3/site-packages/SQLAlchemy-0.91alpha-
> py2.3.egg/sqlalchemy/mapping/objectstore.py", line 305, in commit
> commit_context.execute(echo=echo_commit)
> File "/Library/Python/2.3/site-packages/SQLAlchemy-0.91alpha-
> py2.3.egg/sqlalchemy/mapping/objectstore.py", line 424, in execute
> head.execute(self)
> File "/Library/Python/2.3/site-packages/SQLAlchemy-0.91alpha-
> py2.3.egg/sqlalchemy/mapping/objectstore.py", line 570, in execute
> self.mapper.save_obj(self.tosave_objects(), trans)
> File "/Library/Python/2.3/site-packages/SQLAlchemy-0.91alpha-
> py2.3.egg/sqlalchemy/mapping/mapper.py", line 572, in save_obj
> statement.execute(**params)
> File "/Library/Python/2.3/site-packages/SQLAlchemy-0.91alpha-
> py2.3.egg/sqlalchemy/sql.py", line 400, in execute
> return c.execute(*multiparams, **params)
> File "/Library/Python/2.3/site-packages/SQLAlchemy-0.91alpha-
> py2.3.egg/sqlalchemy/sql.py", line 290, in execute
> return self.engine.execute_compiled(self, params)
> File "/Library/Python/2.3/site-packages/SQLAlchemy-0.91alpha-
> py2.3.egg/sqlalchemy/engine.py", line 533, in execute_compiled
> proxy(str(compiled), parameters)
> File "/Library/Python/2.3/site-packages/SQLAlchemy-0.91alpha-
> py2.3.egg/sqlalchemy/engine.py", line 528, in proxy
> self.execute(statement, parameters, connection=connection,
> cursor=cursor)
> File "/Library/Python/2.3/site-packages/SQLAlchemy-0.91alpha-
> py2.3.egg/sqlalchemy/engine.py", line 582, in execute
> self._execute(cursor, statement, parameters)
> File "/Library/Python/2.3/site-packages/SQLAlchemy-0.91alpha-
> py2.3.egg/sqlalchemy/engine.py", line 592, in _execute
> c.execute(statement, parameters)
> psycopg.IntegrityError: null value in column "id" violates not-null
> constraint
>
>
> Previously, I had noticed that it was selecting from the sequence
> (even though I hadn't defined it) before it did the insert. Now it
> looks like it's just trying to insert NULL. IMHO neither of those are
> correct. It should insert without the primary key column(s) if the PK
> column(s) has not been set and there is no sequence for the column
> (or a sequence has optional=True).
>
> Note, the above code works if I explicitly define the sequence in the
> SA Table.
>
> ~ Daniel
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log
> files
> for problems? Stop! Download the new AJAX search engine that makes
> searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Sqlalchemy-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
>
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users