Baboo7 / strapi-plugin-import-export-entries

Import/Export data from and to your database in just few clicks.
175 stars 86 forks source link

Imports never retain the specified ID, and localizations do not match #165

Closed amityweb closed 3 hours ago

amityweb commented 7 months ago

I am having an awful time with this! I cannot explain it. I have 9 localizations and 36 pages in each. I have a json in one big file. When I import them, I initially get an error saying "Key (id)=(1) already exists.", but maybe its not related, I think its because I am also importing related data in other content types and those IDs do not exist yet, because when I run it again it imports OK.

BUT the issue is, the IDs in the database do not all match the ones in my import. And then the localization IDs I have set are not correct. Some are, it seems to be specific languages. Italian for example is messed up, but German is OK.

I cannot explain it. Has anyone come across this issue? I do not know how to fix it.

Even if I choose a fieldId for a custom field I have its the exact same issue.

What may be throwing it out is some pages are not even imported. Here is a page in French, after importing several times, its not in the DB and some other pages missing. This entry is exactly the same as others, except it has its own sequenced unique ID of 37. Its the first entry after the default language entries. Instead there is a random German page in the DB at ID 37 which is supposed to have ID 110! IS 110 is a Korean page thats supposed to be 153. So on so forth. This entry's localizations work, e.g. entry 37 is linked to entry 1, but entry 37 is the wrong one.

How can the import system honour the IDs? It does for the default language, the first 36 entries, then goes off on one from 37 onward!

I tried it without the é in the title thinking maybe its character related but same issue.

"37":{
    "id":"37",
    "title":"Actualités",
    "craftId":"489005-fr",
    "Sections":[

    ],
    "slug":"actualites",
    "locale":"fr",
    "localizations":[
        1
    ],
    "createdAt":"2019-07-23T01:54:15.000Z",
    "updatedAt":"2023-04-01T15:33:48.000Z",
    "publishedAt":"2019-07-23T01:54:00.000Z",
    "createdBy":"4",
    "updatedBy":"4"
},

Thanks

amityweb commented 7 months ago

I have just noticed I have LOADS of these errors in console when I try to import, but I think only the first time when I get the id error above. I dont get any errors when I re-import again.

[2024-01-12 00:26:16.348] error: 2 errors occurred
ValidationError: 2 errors occurred
    at handleYupError (/my-dev-folder/node_modules/@strapi/utils/dist/index.js:410:9)
    at /my-dev-folder/node_modules/@strapi/utils/dist/index.js:420:7
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.create (/my-dev-folder/node_modules/@strapi/strapi/dist/services/entity-service/index.js:122:23)
    at async Object.<anonymous> (/my-dev-folder/node_modules/@strapi/strapi/dist/services/entity-service/index.js:309:18)
    at async Object.create (/my-dev-folder/node_modules/@strapi/plugin-i18n/dist/server/index.js:3213:19)
    at async /my-dev-folder/node_modules/@strapi/plugin-i18n/dist/server/index.js:3336:20
amityweb commented 7 months ago

Lastly, maybe related.. by default the import options show a list of all fields I could choose as the fieldId. It chooses ID by default.

If I add the below in the content type schema.json, all the fields disappear and I am only left with ID. I do not know if its intentional and it nevertheless uses by custom idField or not. But I get the same issue whether I choose ID or idField anyway.

  "pluginOptions": {
    "i18n": {
      "localized": true
    },
    "import-export-entries": {
      "idField": "craftId"
    }
  },
amityweb commented 7 months ago

Dont worry about this, my mistake. In the following, the first number 37 seems it can be ANYTHING, even random characters, and is not used. The second 37 is the entry ID, but for additional locales, instead of carrying on the ID that Strapi would use I had to start with ID 1. Strapi creates it with ID 37 though.

"api::page.page": {
    "37": {
        "id": 37,

Its very confusing because I need to add the entry with id: "1" and then Strapi creates it with ID 37 (as I have 36 entries in English and this is the first entry in French), but I can then edit that entry using either id: "1" OR id: "37" !!

amityweb commented 7 months ago

Still cannot get the IDs to match the ones I create. I think your importer or strapi is adding them in a different order and so different IDs than in my import file.

The only way I can seem to import it how I want is:

1) Import locales one at a time - then the IDs that I set are honoured 2) Do not import locale entries that do not have a localization - if I do, the non-localized entry is still localized to the wrong page in the default language which results in a few other pages not importing, like something is all out of whack.