Skip to content

Fix descending index KeyError and missing FK columns in table definitions#41

Open
dav-m85 wants to merge 1 commit into
makecodes:mainfrom
dav-m85:fix/descending-index-and-fk-columns
Open

Fix descending index KeyError and missing FK columns in table definitions#41
dav-m85 wants to merge 1 commit into
makecodes:mainfrom
dav-m85:fix/descending-index-and-fk-columns

Conversation

@dav-m85
Copy link
Copy Markdown

@dav-m85 dav-m85 commented May 21, 2026

  • Strip leading '-' from field names in add_meta_indexes before looking up in _forward_fields_map, fixing a KeyError when indexes use descending fields (e.g. fields=["-timestamp"]).
class AuditLog(models.Model):
    timestamp = models.DateTimeField(...)

    class Meta:
        indexes = [
            models.Index(fields=["-timestamp"]),  # crashes django-dbml
        ]
  • Emit FK and OneToOneField columns into table.fields before continuing, fixing "ref error: column not found" in dbdiagram.io caused by ref lines referencing columns that were never declared in the table body. This caused "ref error: column not found" when importing the DBML into dbdiagram.io. Fixed by calling build_field_definition and add_field_index for these fields before the continue, matching the pattern used for regular fields.
class Reception(models.Model):
    supplier = models.ForeignKey(Supplier, ...)  # supplier_id never appears in table body

    # Generated DBML would have:
    # ref: purchasing.Reception.supplier_id > catalog.Supplier.id
    # ...but no "supplier_id" column in the Table block → dbdiagram.io ref error

I hope you won't mind me vibecoding this, I'm more a gopher than a pythonist.

Thanks for your software, saved me a lot of time 🙇

…ions

- Strip leading '-' from field names in add_meta_indexes before looking
  up in _forward_fields_map, fixing a KeyError when indexes use
  descending fields (e.g. fields=["-timestamp"]).

- Emit FK and OneToOneField columns into table.fields before continuing,
  fixing "ref error: column not found" in dbdiagram.io caused by ref
  lines referencing columns that were never declared in the table body.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant