On 01/12/2012 17:49, junepeach wrote:
I have 2 simple tables defined as below:
class Test1(Base):
     __tablename__ = 'test1'
     id = Column(Integer, primary_key = True)
     name = Column(String(15))

class Test2(Base):
     __tablename__ = 'test2'
     fid = Column(Integer, ForeignKey('test1.id'))
     tname = Column(String(15))

You can see that Test2 is a table without a primary key. When I run 'alembic 
revision --autogenerate' to create migration script, and got below error:
   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/__init__.py", 
line 1129, in mapper
     return Mapper(class_, local_table, *args, **params)
   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/mapper.py", line 
203, in __init__
     self._configure_pks()
   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/mapper.py", line 
767, in _configure_pks
     (self, self.mapped_table.description))
sqlalchemy.exc.ArgumentError: Mapper Mapper|Test2|test2 could not assemble any 
primary key columns for mapped table 'test2'

So I wonder how to create a migration script for a table without primary key. 
Non-primary key is not good design, but acceptable in mysql, sqlite, postgresql.
Not an expert, but above is using the SA orm which requires a primary key, you need to define the table using:
http://sqlalchemy.readthedocs.org/en/rel_0_8/core/schema.html#metadata-describing

Werner

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