-
Notifications
You must be signed in to change notification settings - Fork 867
Export/Import does not work properly #4216
Comments
Most of the time, its fails in my environment. |
I am still unable to reproduce on a Mac. I will try on a cloud Linux box but can you please provide me with a screenshot of the error so that I can try to reproduce that error and might follow the stack trace if there is any |
my console output: rm -rf .import/;node_modules/.bin/prisma reset -f ;node_modules/.bin/prisma delete -f;node_modules/.bin/prisma deploy;node_modules/.bin/prisma import --data /tmp/prismaLocal1.zip &> out1.txt Changes: Obj (Type)
Code (Type)
CodeToObj (Relation)
Applying changes 1.1s Your Prisma GraphQL database endpoint is live: HTTP: http://localhost:4466/exportImport/dev Unzipping... 60ms Validating data... 103ms Uploading nodes... Uploading lists Uploading relations and so on (~2370 items) |
I'm having the same issue, I posted about it here: https://www.prisma.io/forum/t/prisma-import-error-after-export/6159/4 |
If this is not production, you can try to use |
It is already done in my case. |
Then, would it be possible for you to provide the export file, |
Already available in git clone https://github.com/slg1/prismaExportImport.git |
I am still unable to reproduce this :/ |
i am same issue "Failure inserting into relationtable _UserPostLinkProducts with ids StringIdGCValue(cjti4si2m50zg0759qwmkxph6) and StringIdGCValue(cju13d77k26qe0741001wydmf). Cause: insert or update on table "_UserPostLinkProducts" violates foreign key constraint "_UserPostLinkProducts_A_fkey"\n Detail: Key (A)=(cjtcjchll29ja0759s8del97d) is not present in table "Product".", |
@leoincedo Can you please provide a reproduction? |
I have the same issue. I tried to find a reason and realized that this is not a problem of import process. The root of problem is broken data in zip: the same relation occurs twice in list of relations. I can't provide whole ZIP (because of private data), but I can provide one JSON with duplicated relations: https://gist.github.com/braska/1803a6c47a512f739a6e8b33d30e1c92 Try to find So because of this duplication I see this error while import:
Another (potentially important) thing I discovered: there is workaround. If I restart PostgreSQL and Prisma before exporting, sometimes Prisma gives the right ZIP without errors. |
I was having the same issues, and I think it was because of the locally created |
this has something to do with .import cache. Deleting the folder and trying to import again worked |
I have already noticed this problem. It has been already mentioned in the above "Import section": |
I did recently some tests, and it seems that the export function generates some duplicated items when more than 1 relation (search ck2vzlpn6bl1n0822bm2e3d1z code in the following files) Database is safe. |
I have the same problem concerning prisma export/import. |
@pantharshit00 @timsuchanek I just want to say that this bug prevent to migrate to new datamodel (https://www.prisma.io/docs/1.31/releases-and-maintenance/features-in-preview/datamodel-v11-b6a7/#4.-optimizing-the-database-schema) Exporting/importing is only one way to get rid of redundant TABLE relations (convert it to INLINE). I already shared the exact description of a problem here: prisma/prisma#4216 (comment) but I can share datamodel if it will help to resolve this issue. |
I ran into this problem as well when trying to pull in my data export from my prisma v1.30 data into a new initialized database with v1.34. I found the problem is that the I didn't have a .import cache folder when I saw the error so that was not the issue for me. Inside the export zip file in the relations folder you will likely see duplicates of many of the "rows" leading to this error. I wrote a script that detects all duplicate relation rows and prints them out to the console (it prints out the id value of each relation column in the affected relation row. I then used the first id from relationA and searched the files for these and removed them): https://gist.github.com/inlightmedia/3cbf08918f3c4bcd474be73a9b5991ec You could extend this script to remove the duplicates as well. For now it just finds them and prints them and lets you do the deleting. Once I sanitized the data (removing all duplicates) I zipped the 3 folders (nodes, lists, and relations) then sent the zip file to my server to be imported. When importing this "sanitized" exportedData I used the following in the folder containing the prisma.yml config file. With that, everything worked! Hope this saves someone some time. God bless! |
Describe the bug
Import of a previous export does not work properly with the following message:
Failure inserting into relationtable _CodeToObj with ids StringIdGCValue(cjtflw2ilq6qp08799l21x89r) and StringIdGCValue(cjtfly6jxroq50879hp2avno8). Cause: duplicate key value violates unique constraint "_CodeToObj_AB_unique"\n Detail: Key ("A", "B")=(cjtflw2biq6ni08798alm3tyl, cjtflwoqeqlnj0879ijz8xb29) already exists.
To Reproduce
Clone the repository:
get prisma token and copy in the index.js
npm install npm-run
./node_modules/.bin/npm-run prisma token
copy token in index.js file
run index.js to load database
node_modules/.bin/prisma reset -f ;node_modules/.bin/prisma delete -f;node_modules/.bin/prisma deploy;node index.js
export
rm -f /tmp/prismaLocal.zip;node_modules/.bin/prisma export --path /tmp/prismaLocal.zip
import
rm -rf .import/;node_modules/.bin/prisma reset -f ;node_modules/.bin/prisma delete -f;node_modules/.bin/prisma deploy;node_modules/.bin/prisma import --data /tmp/prismaLocal.zip
result of test
Observe several traces in console (if no traces are print, redo the test from "run index.js to load database")
"Failure inserting into relationtable _CodeToObj with ids StringIdGCValue(cjtfka7a2oglf0879ofll120t) and StringIdGCValue(cjtfkcdgypylu0879k2k9a994). Cause: duplicate key value violates unique constraint "_CodeToObj_AB_unique"\n Detail: Key ("A", "B")=(cjtfka74nogi80879crln0530, cjtfkas5povi90879pqlt43c7) already exists."
Expected behavior
All relations from previous export should be imported properly
Screenshots
None
Versions (please complete the following information):
OS: centos-release-7-4.1708.el7.centos.x86_64
Linux fdcd67765900 3.10.0-514.21.2.el7.x86_64 #1 SMP Tue Jun 20 12:24:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
prisma: 1.15.3 and prisma-binding: 2.1.5: always fails
prisma: 1.27.3 and prisma-binding: 2.3.0: very often fails
prisma: 1.28.5 and prisma-binding: 2.3.9: very often fails
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: