django-firebird icon indicating copy to clipboard operation
django-firebird copied to clipboard

AttributeError: 'ManyToManyField' object has no attribute 'rel'

Open progressify opened this issue 6 years ago • 2 comments

I have dumped data from a Django server and I want to load a fixture in my new Django server with firebird DB. (Django ver. 2.0.13) example command: python manage.py dumpdata auth.User > user.json I receive this error: AttributeError: 'ManyToManyField' object has no attribute 'rel'

I have resolved in this way: \Lib\site-packages\firebird\operations.py old code:

            for f in model._meta.many_to_many:
               if not f.rel.through:
                    table_name = self.quote_name(f.m2m_db_table())
                    column_name = self.quote_name(f.column)
                    sequence_name = get_autoinc_sequence_name(self, f.m2m_db_table())
                    procedure_name = get_reset_procedure_name(self, f.m2m_db_table())
                    output.append(procedure_sql % locals())
                    procedures.append(procedure_name)

this is my solution:

            for f in model._meta.many_to_many:
                try:
                    if not f.rel.through:
                        table_name = self.quote_name(f.m2m_db_table())
                        column_name = self.quote_name(f.column)
                        sequence_name = get_autoinc_sequence_name(self, f.m2m_db_table())
                        procedure_name = get_reset_procedure_name(self, f.m2m_db_table())
                        output.append(procedure_sql % locals())
                        procedures.append(procedure_name)
                except:
                    pass

progressify avatar Oct 04 '19 07:10 progressify

Hi @progressify Silence an exception is not a very good practice because you never could to know what error is happening.

If I remember correctly, the .rel attribute was renamed to remote_field, then maybe the correct modification could be

for f in model._meta.many_to_many:
                try:
                    if not f.remote_field.through:   // change rel to remote_field

I really did not test it.

Regards

maxirobaina avatar Dec 11 '19 19:12 maxirobaina

I know that is not a good practice. I can test for you this modification :)

progressify avatar Dec 17 '19 11:12 progressify