NotImplementedError when calling .alter() (0.13.1)

32 views Asked by At

I am on datajoint python 0.13.1. When executing .alter() on a table in my schema I am getting the following error message:

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-43-f79406c4b690> in <module>
----> 1 MyTable.alter()

/opt/miniconda3/envs/analysis/lib/python3.6/site-packages/datajoint/table.py in alter(self, prompt, context)
    102             del frame
    103         old_definition = self.describe(context=context, printout=False)
--> 104         sql, external_stores = alter(self.definition, old_definition, context)
    105         if not sql:
    106             if prompt:

/opt/miniconda3/envs/analysis/lib/python3.6/site-packages/datajoint/user_tables.py in definition(self)
     75         """
     76         raise NotImplementedError(
---> 77             'Subclasses of Table must implement the property "definition"')
     78 
     79     @ClassProperty

NotImplementedError: Subclasses of Table must implement the property "definition"

What am I doing wrong?

2

There are 2 answers

0
Dimitri Yatsenko On BEST ANSWER

Makes sense. Currently, alter can only change secondary attributes. I cannot yet modify foreign keys, primary key, and indexes. Issue #901 explains this in part: https://github.com/datajoint/datajoint-python/issues/901

The workaround currently is to use SQL ALTER command, which you can issue using dj.conn().query(....). If you show your before and after table definitions, I will be able to generate the full ALTER command.

1
Horst On

One of the problems was that I didn't load the schema code directly. However, then the error message changes to:

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-6-f79406c4b690> in <module>
----> 1 MyTable.alter()

/opt/miniconda3/envs/analysis/lib/python3.6/site-packages/datajoint/table.py in alter(self, prompt, context)
    102             del frame
    103         old_definition = self.describe(context=context, printout=False)
--> 104         sql, external_stores = alter(self.definition, old_definition, context)
    105         if not sql:
    106             if prompt:

/opt/miniconda3/envs/analysis/lib/python3.6/site-packages/datajoint/declare.py in alter(definition, old_definition, context)
    370         raise NotImplementedError('table.alter cannot alter foreign keys (yet).')
    371     if index_sql != index_sql_:
--> 372         raise NotImplementedError('table.alter cannot alter indexes (yet)')
    373     if attribute_sql != attribute_sql_:
    374         sql.extend(_make_attribute_alter(attribute_sql, attribute_sql_, primary_key))

NotImplementedError: table.alter cannot alter indexes (yet)