> >> Per fortuna ti permette di definire le primary key come vuoi tu (ma non > >> di default, in cui vengono usate primary key surrogate). > > > > anche sqlalchemy tende a farti usare primary key surrogate, dico questo in > > quanto considera la PK come non modificabile. Lavoro con sqlalchemy da > > febbraio ed ho dovuto rivedere un po' la struttura dei miei db per poterla > > adattare a sqlalchemy anche se è molto ben fatto. > > > > Davvero? > Nella documentazione non vi è menzione di questa particolarità. > > Probabilmente è una difesa preventiva contro database come MySQL e > SQLite che non supportano l'integrità referenziale (e quindi se cambi > una primary key, tutte le foreign key collegate diventano prive di > significato). > > Segnalalo come bug, credo che le primary key debbano essere modificabili > per i database dove ha senso.
la sua risposta è stata: you generally shouldnt store any "information" in a primary key. primary keys are by definition immutable so SA would likely trip up if you change them. its conceivable that a feature could be added to allow updating the primary key columns but it would add a lot of complexity to the saving mechanism, to support a pattern that generally is not really correct. http://en.wikipedia.org/wiki/Primary_key if you want an extra "check for this condition" step its not totally impossible, although i dont know if I want to add assertions throughout the code for things like this since it will eventually chunk down the performance. feel free to add a ticket to Trac for a "check that primary key columns havent changed, raise exception" feature, id have to consider how non-intrusive that is. L'utima parte si riferisce al fatto che ignora semplicemente senza sollevare errori. Ora solleva errore solo se contemporaneamente campi PK *E* fai altro: from sqlalchemy import * eng = create_engine("sqlite://", echo=False) session = create_session() users = Table('users', eng, Column('user_name', String(30), nullable = False, primary_key = True), Column('user_last_name', String(30), nullable = False)) users.create() users.insert().execute( {'user_name': 'Sam', 'user_last_name': 'Patts'}, {'user_name': 'Sid', 'user_last_name': 'Watts'}, ) class User(object): pass m = mapper(User, users) u = session.query(m).select()[1] #u = m.select()[1] eng.echo = True u.user_name = 'Sandro' u.user_last_name = 'Dentella' session.flush() > A proposito: nella costruzione di una foreign key sono previste le > clausole on update/on delete, (not) deferrable, initially > immediate/deferred? mi pare che siano state recentemente inserite (in SA, nonso in Django) > E' possibile creare indici parziali con PostgreSQL? ovvero? -- Sandro Dentella *:-) http://www.tksql.org TkSQL Home page - My GPL work _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python