Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to make django field names camelCase?

I'm using django with an MSSQL Server backend. I ran inspectdb on a database and it made all my field names lowercase, when they were camelCase before.

I'd like to retain the camelCase (even if it doesn't jive with Python). I found where it does it in the inspectdb.py:

 """
        Modify the column name to make it Python-compatible as a field name
        """
        field_params = {}
        field_notes = []

        new_name = col_name.lower()
        if new_name != col_name:
            field_notes.append('Field name made lowercase.')

Is it safe to remove the col_name.lower(), or is there something that would cause the camelCase to cause issues?

like image 278
Mitch Avatar asked Sep 15 '25 04:09

Mitch


1 Answers

Nope it won't cause issues on the Django layer.

However, as you said, this is not pep8 style compatible and would lead to frustration along the way especially if other python developers got involved, and, as far as i know MSSQL is case insensitive to table/field names.

--Update-- @Wolph has a great suggestion

first_name = models.CharField(..., db_column='FirstName')

As to balance between python style and your legacy database.

like image 101
Ramez Ashraf Avatar answered Sep 16 '25 19:09

Ramez Ashraf