Thank you for the clarification! On Mon, Sep 14, 2009 at 5:47 AM, Michael Bayer <mike...@zzzcomputing.com>wrote:
> > > On Sep 13, 2009, at 7:27 PM, andrei wrote: > > > > > I try to create the table with column: > > > > Column('ends_at', TIMESTAMP, nullable=True, server_default="") > > > > That results to SQL: > > > > CREATE TABLE news ( > > .... > > ends_at TIMESTAMP DEFAULT '', > > .... > > ) > > > > But mysql TIMESTAMP columns are NOT NULL by default, so I get this > > exception: > > > > (1067, "Invalid default value for 'ends_at'") > > > > However, a TIMESTAMP column can be allowed to contain NULL by > > declaring it with the NULL attribute. > > How to add NULL attribute explicitly? so the generated code would be: > > > > CREATE TABLE news ( > > .... > > ends_at TIMESTAMP NULL DEFAULT '', > > .... > > ) > > the MySQL dialect doesn't offer that feature right now. > > Here's a patch against trunk which would accomplish it: > > Index: lib/sqlalchemy/dialects/mysql/base.py > =================================================================== > --- lib/sqlalchemy/dialects/mysql/base.py (revision 6339) > +++ lib/sqlalchemy/dialects/mysql/base.py (working copy) > @@ -1330,7 +1330,9 @@ > > if not column.nullable: > colspec.append('NOT NULL') > - > + elif isinstance(column.type, types.TIMESTAMP): > + colspec.append('NULL') > + > if column.primary_key and column.autoincrement: > try: > first = [c for c in column.table.primary_key.columns > > otherwise for now you'd have to issue that manually or use ALTER TABLE > after the fact to set it up (i'd use DDL() for the ALTER). Or just > use a DATETIME type instead. > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---