ibmdb / python-ibmdb-django

IBM DB2 Driver for the Django application Framework
Apache License 2.0
29 stars 42 forks source link

Bugfix: wrong parameter for _create_index_name + remove invalid m2m check on add_field + added support for changing m2m through fields #23

Closed z1r0- closed 3 years ago

z1r0- commented 6 years ago

I fixed some bugs I experienced with the execution of django migrations:

With the changes for the django 2.0 support one _create_index_name call argument was changed. I guess it happened by mistake, since the other calls weren't:

https://github.com/ibmdb/python-ibmdb-django/pull/18/commits/9ce69f20ec79b6dddfe075287a7cba8f3b50fe14#diff-28dd935d8b6c5de25b8e30186f05ee9eR435

Nevertheless: _create_index_name expects a model as first argument, so this one currently fails if you try to add a unique constraint to an existing field.

The other change refers to: https://github.com/ibmdb/python-ibmdb/pull/319 by @chsymann89 Since the ibm_db_django files on the other repo haven't been updated for years, I picked it up here too. I fully agree with the pull request, because no field operations have to be done for ANY m2m-fields at that point. The base backend of django uses this check to find out if it needs to "autocreate" a through table or not (because it has it's own model). It exits the add_field call for m2m-fields just some lines after it because definition is None (django/db/backends/schema.py:433). Since the parent function is called before the check, the auto_create stuff is already done and we need to exit for every m2m field.

And last one: The base backend of django supports the case that a m2m field with through argument can be changed (auto_create=False for new and old). Currently this is not supported by this db2 adapter. It's an easy one, because nothing has to be done in this case, so I added it (while checking if alter_fields works as expected). I also added an additional Exception-Message if through argument is added or removed by a migration (it's the one django uses).

bimalkjha commented 3 years ago

Already fixed in latest code. Thanks.