ForestAdmin / django-forestadmin

🐍 Django agent for Forest Admin to integrate directly to your existing Django backend application.
https://www.forestadmin.com
GNU General Public License v3.0
122 stars 18 forks source link

Getting error while trying Forest Admin #133

Closed dmarkey closed 1 year ago

dmarkey commented 1 year ago

Expected behavior

No error.

Actual behavior

Stack trace when booting django app.

django.core.exceptions.FieldError: The relation has multiple target fields, but only single target field was asked for

Failure Logs

File "/Users/dmarkey/src/xx/src/xx/urls.py", line 15, in init_forest() File "/Users/dmarkey/src/xxx/venv/lib/python3.10/site-packages/django_forest/init.py", line 11, in init_forest Schema.build_schema() File "/Users/dmarkey/src/xxx/venv/lib/python3.10/site-packages/django_forest/utils/schema/init.py", line 121, in build_schema cls.add_fields(model, collection) File "/Users/dmarkey/src/xxx/venv/lib/python3.10/site-packages/django_forest/utils/schema/init.py", line 111, in add_fields f = cls.handle_relation(field, f) File "/Users/dmarkey/src/xxx/venv/lib/python3.10/site-packages/django_forest/utils/schema/init.py", line 88, in handle_relation f['reference'] = f'{field.related_model._meta.db_table}.{field.target_field.column}' File "/Users/dmarkey/src/xxx/venv/lib/python3.10/site-packages/django/db/models/fields/related.py", line 436, in target_field raise exceptions.FieldError( django.core.exceptions.FieldError: The relation has multiple target fields, but only single target field was asked for

Context

Is there a setting to ignore certain models? I've identified the model and I'm not really that interested in it in Forest Admin

jbarreau commented 1 year ago

Hello @dmarkey, Yes we have a setting to ignore models in forest, but currently missing in the documentation (I will handle this soon). You can use it by modifying your settings.py :

FOREST = {
    'FOREST_ENV_SECRET': os.environ.get('FOREST_ENV_SECRET'),
    'FOREST_AUTH_SECRET': os.environ.get('FOREST_AUTH_SECRET'),
    'EXCLUDED_MODELS': ['django_content_type', 'django_migrations'],
}

Let me know if it works on your side.

Regards.

jbarreau commented 1 year ago

I just updated the documentation for this topic. It is available here: https://docs.forestadmin.com/documentation/extra-help/settings/include-exclude-models

dmarkey commented 1 year ago

Great! I'll try this workaround later.

On the root cause, do you need any further information? I suggest a helpful error message rather than this ugly stack trace at least.

jbarreau commented 1 year ago

That should be great if you can provide me an example of Model (just the relationship) that create this error (if you know which one of your model generate it) because I can't reproduce this error on my side.

Is your project running without django-forestadmin ? That's sounds like a dumb question, but at the end of the stacktrace, there is a Django error, and I can't find on google anything else than source code of Django that deal with this issue.

jbarreau commented 1 year ago

I closed this issue because it stale.