ibmdb / python-ibmdb-django

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

base.py: disable/enable constraint checking functions do not take schema into account #91

Closed 0x2ec closed 1 year ago

0x2ec commented 1 year ago

For example in disable_constraint_checking:

https://github.com/ibmdb/python-ibmdb-django/blob/a8d5ccf91e4e985e20f0c9832e44a58582c2f230/ibm_db_django/base.py#L415-L437

My current use-case is that I'm trying to do ./manage.py loaddata and it's fails because it tries to disable some constraints for a table in another schema.

I've been working with:

nowhere does it mention anything about the schema, so I get a query like this:

>>> operation = 'ALTER TABLE MYTABLE ALTER FOREIGN KEY SQL230324215718120 NOT ENFORCED;'
Traceback (most recent call last):
  File "/home/tj/o/server/.venv/lib64/python3.9/site-packages/ibm_db_dbi.py", line 1312, in _execute_helper
    return_value = ibm_db.execute(self.stmt_handler, parameters)
Exception: Statement Execute Failed: [IBM][CLI Driver][DB2/LINUXX8664] SQL0204N  "OMNIO.MYTABLE" is an undefined name.  SQLSTATE=42704 SQLCODE=-204

but MYTABLE is a table defined in another schema.

I can see a couple of options:

  1. Somehow figure out how to set table_names so this constraint disabling/enabling is restricted to the tables in the current schema
  2. make this logic schema-aware (the approach I'm investigating now)
  3. try to completely disable this logic (not sure if there's a straight-forward configuration way to do that)