Open pironti opened 4 months ago
I get the same issue. Whenever I try to do a push it does this.
truncate table <table> cascade;
Same Issue here, exactly doing the same process as the Original Poster. The problem seems to be in the push command. Running the migrations using the migrate function (Node.JS) does not cause the same issue.
I'm running into this issue. This is a huge problem. There's no reason to truncate the table when making certain changes to a table. If I change a column type from enum to varchar, allow a column to be null, or set a default value, those are all changes that the database can handle without data loss.
I have to manually run the migration and that's not great.
What version of
drizzle-orm
are you using?0.29.4
What version of
drizzle-kit
are you using?0.20.14
Describe the Bug
When I change a column in the schema and then run the ‘drizzle-kit push:mysql’ command, I receive an error message saying that the migration will cause data loss.”
Schema File
I altered de column user_id from varchar(28) to varchar(30)
Warning message:
THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED
Do you still want to push changes? ❯ No, abort Yes, I want to truncate 1 table
Expected behavior
The expected behavior was for the migration to be executed without requesting user action. I understand this to be a bug, as this migration does not cause any side effects on the database since the column was already nullable, and when I run the generated SQL directly on the database, no errors occur.
As shown:
Generated migration:
Running the generated SQL directly on the database:
Environment & setup
Create schema:
Run commands:
npx drizzle-kit generate:mysql
npx drizzle-kit push:mysql
Alter schema:
Run commands:
npx drizzle-kit generate:mysql
npx drizzle-kit push:mysql