not sure.  make sure you're on 0.5.3.   do the unit tests included with
the recipe pass ?


Suha Onay wrote:
> Thanks for the recipe.I faced with an error.
>
> The model is now:
> ------------------------------------------------------------------------------
> from history_meta import VersionedMeta
>
> Base = declarative_base(metaclass=VersionedMeta)
>
> class User(Base):
>     __tablename__ = 'users'
>
>     id = sa.Column(sa.Integer, primary_key=True)
>     name = sa.Column(sa.Unicode(12))
>     fullname = sa.Column(sa.Unicode(40))
>     password = sa.Column(sa.Unicode(20))
>     active = sa.Column(sa.Boolean())
>     type = sa.Column(sa.SmallInteger())
>     note = sa.Column(sa.Text())
>     date_created = sa.Column(sa.Date())
> ------------------------------------------------------------------------------
> Session = sessionmaker(bind=engine, autocommit=False, autoflush=True,
> expire_on_commit=False, extension=VersionedListener())
> ------------------------------------------------------------------------------
>
> When inserting a new user, the error occurs:
> sqlite3: <class 'sqlalchemy.exc.IntegrityError'> -=> ('(IntegrityError)
> users.version may not be NULL',)
> postgre: <class 'sqlalchemy.exc.IntegrityError'> -=> ('(IntegrityError)
> null
> value in column "version" violates not-null constraint\n',)
>
> The code in history_meta creates the column version with default value 1:
> cls.version = Column('version', Integer, default=1, nullable=False)
>
> What is the reason?
> Thanks.
>
> Suha
>
>
>
> On Wed, Mar 25, 2009 at 17:17, Michael Bayer
> <mike...@zzzcomputing.com>wrote:
>
>>
>> I've placed a recipe for this on the wiki at
>> http://www.sqlalchemy.org/trac/wiki/UsageRecipes/LogVersions
>>  .
>>
>>
>> On Mar 25, 2009, at 10:12 AM, Suha Onay wrote:
>>
>> >
>> > Hi,
>> >
>> > I am using sqlalchemy for a while in a project.
>> > The project has lots of models like User:
>> >
>> ------------------------------------------------------------------------------
>> > from mcmodel import MCModel
>> >
>> > Base = declarative_base()
>> >
>> > class User(MCModel, Base):
>> >    __tablename__ = 'users'
>> >
>> >    id = sa.Column(sa.Integer, primary_key=True)
>> >    name = sa.Column(sa.Unicode(12))
>> >    fullname = sa.Column(sa.Unicode(40))
>> >    password = sa.Column(sa.Unicode(20))
>> >    active = sa.Column(sa.Boolean())
>> >    type = sa.Column(sa.SmallInteger())
>> >    note = sa.Column(sa.Text())
>> >    date_created = sa.Column(sa.Date())
>> >
>> ------------------------------------------------------------------------------
>> > All of these models inherit from MCModel (nothing doing special).
>> >
>> > I want to save all the changes done to a user in a seperate db table
>> > like "_hist_users".
>> > The new inserts do not need to be in the hist table.
>> > When a user is updated, the old data of the user will be copied to the
>> > hist table with a column declaring this is an update operation.
>> > When a user is deleted, the old data of the user will be moved to the
>> > hist table with a column declaring this is a delete operation.
>> > With these operations, it is possible to know who modified what and
>> > when.
>> >
>> > How can i achieve in this?
>> > By modifying the MCModel to enable all the models aware of history
>> > backup?
>> > Or using class sqlalchemy.orm.interfaces.MapperExtension.after_update
>> > methods? (i do not know how)
>> > Or anything else?
>> >
>> > Thanks in advance.
>> >
>> > Suha
>> >
>> >
>> >
>> >
>> >
>> >
>> > >
>>
>>
>> >
>>
>
> >
>


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to