问题描述
我正在尝试使用dajngo-import-export库通过django admin将数据导入模型中,尽管我遇到了“配置不正确”错误。 这是错误消息:
ImproperlyConfigured at /admin/pages/quote/import/
No exception message supplied
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/pages/quote/import/
Django Version: 3.0
Exception Type: ImproperlyConfigured
Exception Location: C:\Users\Dell\.virtualenvs\read_bus-UfMQ3ck8\lib\site-packages\import_export\resources.py in import_data,line 737
Python Executable: C:\Users\Dell\.virtualenvs\read_bus-UfMQ3ck8\Scripts\python.exe
Python Version: 3.7.3
Python Path:
['C:\\Users\\Dell\\Downloads\\read_bus','C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\Scripts\\python37.zip','C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\DLLs','C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib','C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\Scripts','c:\\users\\dell\\anaconda3\\Lib','c:\\users\\dell\\anaconda3\\DLLs','C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8','C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages','C:\\Users\\Dell\\Downloads\\read_bus','C:\\Users\\Dell\\.virtualenvs\\read_bus-UfMQ3ck8\\lib\\site-packages\\odf',]
我正在遵循here所述的文档。
这是admin.py文件:
class QuoteResource(resources.ModelResource):
class Meta:
model =Quote
import_id_fields=('quote',)
fields = ('quote','book','author',)
class QuoteAdmin(ImportExportModelAdmin):
list_display=('quote','author')
resource_class =QuoteResource
admin.site.register(Quote,QuoteAdmin)
我尝试使用'QuoteResource'和不使用'QuoteResource'都没有成功。
我成功地能够从管理员导出数据。但是在导入过程中面临挑战。导入过程中的管理员片段:
以下是我尝试导入数据的多种方式之一:
它与Django设置或csv数据格式有关吗?
如果需要更多信息,请告诉我。
解决方法
您的错误来自尝试使用数据库事务但不支持事务的导入导出。因此,这是数据库的问题。
django-import-export的代码部分可在此处查看:https://github.com/django-import-export/django-import-export/blob/master/import_export/resources.py#L737
要禁用交易,请添加设置并使其为false; IMPORT_EXPORT_USE_TRANSACTIONS
。