Skip to content
1 change: 1 addition & 0 deletions ormar/fields/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ def get_column(self, name: str) -> sqlalchemy.Column:
self.column_type,
*self.construct_constraints(),
primary_key=self.primary_key,
autoincrement=self.autoincrement,
nullable=self.sql_nullable,
index=self.index,
unique=self.unique,
Expand Down
19 changes: 19 additions & 0 deletions tests/test_model_definition/test_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class Example(ormar.Model):
size: MyEnum = ormar.Enum(enum_class=MyEnum, default=MyEnum.SMALL)


class ExampleNonAutoIncrement(ormar.Model):
ormar_config = base_ormar_config.copy(tablename="example_nonautoincrement")

id: int = ormar.Integer(primary_key=True, autoincrement=False)
name: str = ormar.String(max_length=200, default="aaa")


class EnumExample(ormar.Model):
ormar_config = base_ormar_config.copy(tablename="enum_example")

Expand All @@ -59,6 +66,18 @@ class WrongEnum(Enum):
Example(size=WrongEnum.A)


@pytest.mark.asyncio
async def test_non_auto_increment_pk():
async with base_ormar_config.database:
example = ExampleNonAutoIncrement(id=1)
await example.save()

assert (
ExampleNonAutoIncrement.ormar_config.table.columns["id"].autoincrement
is False
)


@pytest.mark.asyncio
async def test_enum_bulk_operations():
async with base_ormar_config.database:
Expand Down
Loading