| Version 4 (modified by ged, 5 years ago) |
|---|
- Is there a way to specify the primary key manually?
- Is there a way to declare uniqueness constraints?
Is there a way to specify the primary key manually?
Yes, add primary_key=True to your field definition. Here is an example:
class Person(Entity): person_id = Field(Integer, primary_key=True) firstname = Field(Unicode(30)) surname = Field(Unicode(30))
This also works if your primary key is composed of several fields:
class Person(Entity): firstname = Field(Unicode(30), primary_key=True) surname = Field(Unicode(30), primary_key=True)
Is there a way to declare uniqueness constraints?
Yes, you can use the using_table_options statement in combination with SQLAlchemy's UniqueConstraint. Here is an example:
from sqlalchemy import UniqueConstraint class Person(Entity): firstname = Field(Unicode(30)) surname = Field(Unicode(30)) using_table_options(UniqueConstraint('firstname', 'surname'))
