Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the column naming in database : ({col_name}_id_id) thing #461

Open
MahmoudNasser01 opened this issue Jan 14, 2025 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@MahmoudNasser01
Copy link
Contributor

Feature Request

In many columns when it is reflect on the database most of the names have this pattern ({col_name}_id_id) it is pretty annoying.

Description

What I suggest is to make the columns names in django models to be for example department instead of department_id and so one since django add suffix _id by its own

Use Case

[Explain how this feature would be useful and how it fits into the project's context.]

Proposed Solution

What I suggest is to make the columns names in django models to be for example department instead of department_id and so one since django add suffix _id by its own

Benefits

clear database naming

Labels

enhancement

Priority

medium

@horilla-opensource horilla-opensource added the enhancement New feature or request label Jan 15, 2025
@horilla-opensource
Copy link
Owner

Hi @MahmoudNasser01,

Thank you for bringing up this issue and for the detailed explanation, Django automatically adds the _id suffix to foreign key fields, which can lead to redundancy when naming columns in the database, such as department_id_id.

Use Case

We understand that clear and concise naming in the database is crucial for readability and maintenance. Redundant suffixes can cause confusion and clutter, especially when working directly with the database or in raw SQL queries.

Proposed Solution

To address this, we propose leveraging Django's db_column attribute in model fields. This allows us to specify custom column names directly, avoiding the double _id suffix issue. For instance:

class EmployeeWorkInformation(models.Model):
    department = models.ForeignKey(Department, on_delete=models.CASCADE, db_column='department')

This way, the actual database column will be named department instead of department_id.

Next Steps

We'll evaluate the impact of implementing this change across the project and consider including it in future updates. If anyone has additional thoughts or concerns, please share them here.

Thanks again for your suggestion and contribution to improving our project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants