I've read the docs on this and thought I understood, but I can't get it 
to work.  I define a table like so:

actions = Table('actions', metadata,
     Column('id', INTEGER, primary_key=True),
     Column('name', VARCHAR(100), nullable=False),
     Column('suser_name', VARCHAR(100), nullable=False),
     Column('action_time', DATETIME, nullable=False,
         default=func.CURRENT_TIMESTAMP),
     Column('notes', TEXT),
     Column('project_id', INTEGER,
         ForeignKey("%s.projects.id" % schemaname), nullable=False),
     Column('input_time', DATETIME, nullable=False,
         default=func.CURRENT_TIMESTAMP),
     schema=schemaname
)

Note the action_time column with a default value of 
func.CURRENT_TIMESTAMP.  Here is the output from 
planreview.metadata.create_all():

CREATE TABLE planreview.actions(
         id SERIAL NOT NULL PRIMARY KEY,
         name VARCHAR(100) NOT NULL,
         suser_name VARCHAR(100) NOT NULL,
         action_time TIMESTAMP NOT NULL,
         notes TEXT,
         project_id INTEGER NOT NULL REFERENCES planreview.projects(id),
         input_time TIMESTAMP NOT NULL
)

Now, I attempt an insert.

dws_dev=# insert into planreview.actions (name, suser_name, notes, 
project_id) values ('test', 'test', 'test', 1);

And get an error.

ERROR:  null value in column "action_time" violates not-null constraint

Why isn't the default value defined?  I'm using SA SVN 1593 and PG 7.4. 
  Here is the table definition.

dws_dev=# \d planreview.actions
                                        Table "planreview.actions"
    Column    |            Type             | 
Modifiers
-------------+-----------------------------+-------------------------------------------------------------
  id          | integer                     | not null default 
nextval('planreview.actions_id_seq'::text)
  name        | character varying(100)      | not null
  suser_name  | character varying(100)      | not null
  action_time | timestamp without time zone | not null
  notes       | text                        |
  project_id  | integer                     | not null
  input_time  | timestamp without time zone | not null
Indexes:
     "actions_pkey" primary key, btree (id)
Foreign-key constraints:
     "$1" FOREIGN KEY (project_id) REFERENCES planreview.projects(id)


Note that I also tried a default values of func.now and func.now()

Randall



_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to