Your schema is broken. You can fix it in either of two ways:
- use the natural key in foreign keys as well and drop the surrogate key
- designate the surrogate key as the PK and just make a unique
constraint covering the natural key columns
-Jonathan
If the table has its primary key defined by "name" and "city", typical
relational design would dictate that you wouldn't have an "id" at all,
and theres no issue with this. Foreign keys from other tables would
just have their own "name" and "city" columns that reference the
manufacturer table, this is called a composite foreign key. If you
truly wanted to generate the "id", a database like Postgres would
supply sequences which you can use, but the best you can do in MySQL
is to build your own ID generation function which you can wire in via
sqlalchemy using the "default" keyword to Column.
However if you truly want a surrogate primary key, i wouldnt modify
the schema just to suit the merge() method. What's wrong with the
__new__() strategy I gave you at http://groups.google.com/group/sqlalchemy/browse_thread/thread/79736ff7ef81d1b9/0b80b54dc45ecc28?hl=en&lnk=gst&q=__new__#0b80b54dc45ecc28
? (or is this just google groups delivering emails a week late
again ?)