🐛 Support apps without any models

This commit is contained in:
Brian Wiborg 2025-10-10 15:48:40 +02:00
parent e1f5ce589c
commit 3e15aa7722
No known key found for this signature in database

View file

@ -154,7 +154,10 @@ class Project:
tortoise_cfg = self.build_tortoise_config(db_url=db_url)
# Prevent leaking other app's models to Aerich.
tortoise_cfg["apps"] = {app_label: tortoise_cfg["apps"][app_label]}
if app_label in tortoise_cfg["apps"].keys():
tortoise_cfg["apps"] = {app_label: tortoise_cfg["apps"][app_label]}
else:
tortoise_cfg["apps"] = {app_label: {"default_connection": "default", "models": []}}
# Append aerich.models to the models list of the target app only
tortoise_cfg["apps"][app_label]["models"].append("aerich.models")
@ -403,7 +406,7 @@ class App:
"""
return {
"models": [
f"{self.name}.{m.__name__}" for m in self.models[f"{self.name}.models"]
f"{self.name}.{m.__name__}" for m in self._models[f"{self.name}.models"]
],
"middlewares": self.__serialize_middleware(),
"routes": self.__serialize_router(),