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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With