Hi everyone,
I am architecting a Student Management System (SMS) using Django 6.x as the backend and PostgreSQL as the primary database. The project has a unique requirement: it serves both Web users (via sub-domains) and Offline clients (using MS Access via a central REST API).
We are using UUIDs for all primary keys to ensure data integrity during offline-to-online synchronization. Currently, I am debating the naming convention for Primary Keys (PK) to avoid confusion and conflicts during complex joins and API payloads.
I would love to get the community’s insight on which PK naming convention would be most maintainable in the long run, especially when considering Foreign Key (FK) referencing.
The options I am considering:
-
id (The Django Default): Standard convention, but can lead to ambiguous column names in raw SQL joins.
-
{table}_id (e.g., student_id): Matches the FK name in related tables, making joins explicit and API payloads clearer.
-
id_{table} (e.g., id_student): Less common, but keeps all ID columns grouped together in alphabetical views.
-
{table}_pk (e.g., student_pk): Explicitly identifies the primary key, but differs from the FK name (student_id).
My context:
-
Multi-tenancy: All tables include an institute_id (FK).
-
Hybrid Sync: MS Access clients push and pull data. Using student_id as the PK appears to align well with FK naming and sync logic, but I’m curious whether this introduces unseen issues within Django.
-
Scalability: We plan to integrate an LMS and a Mobile App in the future.
My questions:
-
From a Django perspective, does overriding the default id with
{table}_id(usingprimary_key=True) cause significant friction with Django internals or third-party packages? -
Which convention is most effective at preventing ambiguous column issues during complex reporting and cross-database syncing?
-
Is there a performance or best-practice reason to prefer the generic
ideven in a multi-platform, offline-capable environment?
Looking forward to your expert opinions and real-world experiences.