cloudflare / workers-sdk

โ›…๏ธ Home to Wrangler, the CLI for Cloudflare Workersยฎ
https://developers.cloudflare.com/workers/
Apache License 2.0
2.68k stars 701 forks source link

๐Ÿ› BUG: Export data sql from d1 #7136

Open nmthangdn2000 opened 1 day ago

nmthangdn2000 commented 1 day ago

Which Cloudflare product(s) does this pertain to?

D1

What version(s) of the tool(s) are you using?

3.60.3[wrangler]

What version of Node are you using?

20.14.0

What operating system and version are you using?

Mac sonoma 14.6.1

Describe the Bug

Hello, I am working with D1 and encountering an issue with exporting. I would greatly appreciate any help I can get.

My steps are as follows:

  1. Create database

CREATE TABLE "Movie" ( "id" TEXT NOT NULL PRIMARY KEY, "idSource" INTEGER NOT NULL, "name" TEXT NOT NULL, "nameVi" TEXT NOT NULL, "totalViews" INTEGER NOT NULL, "monthlyViews" INTEGER NOT NULL, "genre" TEXT NOT NULL, "cast" TEXT NOT NULL, "director" TEXT NOT NULL, "country" TEXT NOT NULL, "year" INTEGER NOT NULL, "releaseDate" TEXT NOT NULL, "updateDate" TEXT NOT NULL, "cover" TEXT NOT NULL, "description" TEXT NOT NULL, "trailer" TEXT NOT NULL, "imdbRating" TEXT NOT NULL, "quality" TEXT NOT NULL, "episodesCount" INTEGER NOT NULL, "episodes" TEXT NOT NULL );

  1. Import a new data

Command: npx wrangler d1 execute movie-d1 --local --command="INSERT INTO movie (id, idSource, name, nameVi, totalViews, monthlyViews, genre, cast, director, country, year, releaseDate, updateDate, cover, description, trailer, imdbRating, quality, episodesCount, episodes) VALUES ('abc123', 1, 'Movie Title', 'Movie Title', 1000, 200, 'Action', 'Actor 1, Actor 2', 'Director Name', 'Country Name', 2024, '2024-01-01', '2024-01-01', 'http://example.com/cover.jpg', 'Description of the movie', 'http://example.com/trailer.mp4', 8.5, 'HD', 10, 'Episode 1, Episode 2');"

CleanShot 2024-10-31 at 15 23 17@2x CleanShot 2024-10-31 at 15 25 10@2x

  1. Export data

Command npx wrangler d1 export movie-d1 --local --output=./database.sql

CleanShot 2024-10-31 at 15 26 31@2x

The error I encountered is quite challenging, making it difficult for me to test and resolve the issues. I would sincerely appreciate any assistance you can provide. Thank you!

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

--- 2024-10-31T08:36:49.764Z debug ๐Ÿชต Writing logs to "/Users/vacs-imac/Library/Preferences/.wrangler/logs/wrangler-2024-10-31_08-36-48_939.log"

--- 2024-10-31T08:36:49.764Z log

โ›…๏ธ wrangler 3.83.0 (update available 3.84.0) -------------------------------------------------------


--- 2024-10-31T08:36:49.765Z debug No experimental flag store instantiated

--- 2024-10-31T08:36:49.765Z debug Attempted to use flag "JSON_CONFIG_FILE" which has not been instantiated

--- 2024-10-31T08:36:49.770Z log ๐ŸŒ€ Exporting local database movie-d1 (844d6930-e482-4c23-897c-1f74e7194604) from .wrangler/state/v3/d1:

--- 2024-10-31T08:36:49.770Z log ๐ŸŒ€ To export your remote database, add a --remote flag to your wrangler command.

--- 2024-10-31T08:36:50.122Z log ๐ŸŒ€ Exporting SQL to ./database.sql...

--- 2024-10-31T08:36:50.192Z log


nmthangdn2000 commented 1 day ago

After logging the SQL query executed by the export command, I found that it used SELECT to retrieve all fields instead of using SELECT *. Unfortunately, this caused an error due to a column named "cast" in the movie table, which conflicted with the CAST function in SQL. I resolved the issue by renaming the column and successfully completed the export.

Thank you all for your interest!