fix: inspectdb raise KeyError 'int2' for smallint (#401)

* fix: inspectdb raise KeyError 'int2' for smallint

* fix ci error

* no ask confirm for ci

* docs: update changelog
This commit is contained in:
Waket Zheng 2024-12-27 23:49:53 +08:00 committed by GitHub
parent d6a51bd20e
commit f5d7d56fa5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 15 deletions

View File

@ -56,7 +56,9 @@ jobs:
run: poetry run pip install --upgrade "tortoise-orm>=0.23,<0.24"
- name: Install TortoiseORM develop branch
if: matrix.tortoise-orm == 'tortoisedev'
run: poetry run pip install --upgrade "git+https://github.com/tortoise/tortoise-orm"
run: |
poetry run pip uninstall -y tortoise-orm
poetry run pip install --upgrade "git+https://github.com/tortoise/tortoise-orm"
- name: CI
env:
MYSQL_PASS: root

View File

@ -2,6 +2,13 @@
## 0.8
### [0.8.2]**(Unreleased)**
#### Fixed
- fix: inspectdb raise KeyError 'int2' for smallint. ([#401])
[#401]: https://github.com/tortoise/aerich/pull/401
### [0.8.1](../../releases/tag/v0.8.1) - 2024-12-27
#### Fixed
@ -29,19 +36,18 @@
[#395]: https://github.com/tortoise/aerich/pull/395
[#394]: https://github.com/tortoise/aerich/pull/394
[#393]: https://github.com/tortoise/aerich/pull/393
[#376]: https://github.com/tortoise/aerich/pull/376
[#392]: https://github.com/tortoise/aerich/pull/392
[#388]: https://github.com/tortoise/aerich/pull/388
[#386]: https://github.com/tortoise/aerich/pull/386
[#272]: https://github.com/tortoise/aerich/pull/272
[#334]: https://github.com/tortoise/aerich/pull/334
[#284]: https://github.com/tortoise/aerich/pull/284
[#286]: https://github.com/tortoise/aerich/pull/286
[#302]: https://github.com/tortoise/aerich/pull/302
[#378]: https://github.com/tortoise/aerich/pull/378
[#377]: https://github.com/tortoise/aerich/pull/377
[#271]: https://github.com/tortoise/aerich/pull/271
[#376]: https://github.com/tortoise/aerich/pull/376
[#334]: https://github.com/tortoise/aerich/pull/334
[#302]: https://github.com/tortoise/aerich/pull/302
[#286]: https://github.com/tortoise/aerich/pull/286
[#388]: https://github.com/tortoise/aerich/pull/388
[#392]: https://github.com/tortoise/aerich/pull/392
[#284]: https://github.com/tortoise/aerich/pull/284
[#272]: https://github.com/tortoise/aerich/pull/272
[#271]: https://github.com/tortoise/aerich/pull/271
### [0.8.0](../../releases/tag/v0.8.0) - 2024-12-04

View File

@ -56,7 +56,7 @@ class Column(BaseModel):
length = ", ".join(length_parts) + ", "
if self.null:
null = "null=True, "
if self.default is not None:
if self.default is not None and not self.pk:
if self.data_type in ("tinyint", "INT"):
default = f"default={'True' if self.default == '1' else 'False'}, "
elif self.data_type == "bool":
@ -158,11 +158,11 @@ class Inspect:
@classmethod
def int_field(cls, **kwargs) -> str:
return "{name} = fields.IntField({pk}{index}{comment})".format(**kwargs)
return "{name} = fields.IntField({pk}{index}{default}{comment})".format(**kwargs)
@classmethod
def smallint_field(cls, **kwargs) -> str:
return "{name} = fields.SmallIntField({pk}{index}{comment})".format(**kwargs)
return "{name} = fields.SmallIntField({pk}{index}{default}{comment})".format(**kwargs)
@classmethod
def bigint_field(cls, **kwargs) -> str:

View File

@ -16,12 +16,13 @@ class InspectPostgres(Inspect):
@property
def field_map(self) -> FieldMapDict:
return {
"int2": self.smallint_field,
"int4": self.int_field,
"int8": self.int_field,
"int8": self.bigint_field,
"smallint": self.smallint_field,
"bigint": self.bigint_field,
"varchar": self.char_field,
"text": self.text_field,
"bigint": self.bigint_field,
"timestamptz": self.datetime_field,
"float4": self.float_field,
"float8": self.float_field,