You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Generated SQL missing fk in table definition #2119
Expected behavior
Created SQL has all the fields of the table.
Additional context
in tortoise/migrations/schema_editor/base.py _get_model_sql_data creates sql from fields_db_projection which does not contain fk field.
The migration CLI builds an in-memory “state” of historical models for each app (in tortoise/migrations/schema_generator/state.py). When applying a migration, it calls state.reload_models(models_to_reload) for that app. Critically, only the current app’s models are loaded into the state. Any referenced models from other apps are not automatically included.
Activity
fix(migrations): preserve cross-app foreign keys in migration state
fix(migrations): preserve cross-app foreign key columns and constraints…
noy-solvin commentedon Sep 15, 2026
Hi @waketzheng
I've submitted PR #2278 that fixes this issue.
Would love a review whenever you get a chance. Happy to adjust anything
test: tighten cross-app FK assertion to exact SQLite quoting