Opened 8 years ago

Closed 8 years ago

#16741 closed Bug (invalid)

Naming a model field to "num_connections" causes syncdb to seemingly ignore it (mysql)

Reported by: honn@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Normal Keywords: model, field, syncdb, mysql
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Not sure this is a bug or a case of an undocumented restriction.

Naming a model field (in this case a PositiveIntegerField) "num_connections" and doing a syncdb causes the field to be ignored completely. There is no error and the table is create in the database, just without the num_connections field. To check that the model itself is not broken in other ways (and obfuscating the real cause of the problem) I have tried renaming the "num_connections" field to other things and it then works. So it appears that it is the name "num_connections" is somehow restricted.

The database in this case is mysql. Fields with this name can be created by a normal ALTER TABLE so it does not appear to be a problem in mysql but a problem in django.

Consequences: Aside from the obvious, that the column is not created in the database, django does not seem to fully understand that it does not exist. Trying to save data into the field does not seem to crash, it is just ignore. I found the error when doing an order_by on the field, which caused an error as the field did not exist.

This might be a case of num_connection simply being reserved in either python or django but if this is the case I can't find any documentation on the subject.

Change History (1)

comment:1 Changed 8 years ago by honn@…

Resolution: invalid
Status: newclosed

Darn, original reporter here. I just noticed something I didn't notice before. We had added a num_connection function on the model where this refused to work, that was the problem. When I changed the name of the field it naturally started to work as the there was no longer a conflict. So I am closing the bug.

Note: See TracTickets for help on using tickets.
Back to Top