-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Importing fails or raises error for model that contains primary key which is not id #84
Comments
Are you using the same resource for both? |
Yes, I'm using same resource for both. In fact, this same resource is used for export also. Export with |
Sorry, but I've read the stacktrace 3 times now and nothing is occurring to me what could be wrong. The only thing that looks like it might be going down a non-standard path is this
Sorry I couldn't be of more use. |
Could you please tell me which version of |
A quick workaround to this issue, is to change the name of the custom primary key of a foreign key model to id. |
I was looking into this issue and here are some of the things I have found. The error was being raised from this line. Here is the scenario I used for testing. class WinnersResource(ModelResource):
class Meta:
model = Winner
import_id_fields = ('name', )
def get_export_queryset(self):
"""To customise the queryset of the model resource with annotation override"""
return self.Meta.model.objects.all() In the WinnersResource I set The main reason for this behavior is when we are using I tried to create two resource objects one by using the So, what is happening is when we are using So, the solution for this issue as I am thinking could be to mention this in the documentation. If the user is defining custom resource classes for models then they should make sure to mention that resource class in settings in IMPORT_EXPORT_CELERY_MODELS = {
"Winner": {"app_label": "winners", "model_name": "Winner", "resource": WinnersResource}
} So, the resource class defined by users should be used and not the resource created by @xalien10 If you can try this solution and let us know if it fixes this issue then it would be great. @timthelion let me know if you have any comments here... |
But I was hoping to use Though I'haven't tried it may be we can give it a try by the following approach
What do you think about this one? |
This class will be ignored until you do not mention your resource class in |
I was trying to import a model resource whose primary key is not the
id
. And when I'm trying to import it from the celery import admin section but it's failing and raising errors. But the same file is able to create/update rows usingdjango-import-export
import action.This is my model resource
And I'm getting the following errors while importing,
Error with dry run:

Error without dry run

But import was successful with

django-import-export
action and row can be seen on the list:@timthelion
The text was updated successfully, but these errors were encountered: