SQLA doesn't generate those defaults without being told explicitly. Are you
sure you don't have some other table metadata, or perhaps schema events in
place which are adding defaults ?
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Table, CHAR, TIMESTAMP, TEXT, schema, Column
from uuid import uuid4 as uuid
Base = declarative_base()
class Foo(Base):
__tablename__ = 'foo'
#column definitions
id = Column(u'id', CHAR(length=36), default=uuid, primary_key=True,
nullable=False)
date_added = Column(u'dateAdded', TIMESTAMP(), nullable=False)
reason = Column(u'reason', TEXT())
from sqlalchemy.dialects import mysql
print schema.CreateTable(Foo.__table__).compile(dialect=mysql.dialect())
output:
CREATE TABLE foo (
id CHAR(36) NOT NULL,
`dateAdded` TIMESTAMP,
reason TEXT,
PRIMARY KEY (id)
)
On Nov 28, 2011, at 4:45 PM, Ben Hayden wrote:
> Say I have a model (running on MySQL):
>
> class Foo(DeclarativeBase):
> __tablename__ = 'foo'
>
> #column definitions
> id = Column(u'id', CHAR(length=36), default=uuid, primary_key=True,
> nullable=False)
> date_added = Column(u'dateAdded', TIMESTAMP(), nullable=False)
> reason = Column(u'reason', TEXT())
>
>
>
> The Create Table SQL being generated is:
>
> CREATE TABLE `foo` (
> `id` char(36) NOT NULL,
> `dateAdded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE
> CURRENT_TIMESTAMP,
> `reason` text,
> PRIMARY KEY (`id`)
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
>
> I'd like for the dateAdded column to be a dateAdded - not dateUpdated, which
> would leave the Create Table SQL to look like this:
>
> CREATE TABLE `foo` (
> `id` char(36) NOT NULL,
> `dateAdded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
> `reason` text,
> PRIMARY KEY (`id`)
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
>
> Any ideas on how to do this? I keep googlin' around, but setting onupdate or
> server_onupdate doesn't seem to work for me (yet...) Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sqlalchemy/-/36ZXHV5mZMIJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.