Closed mrbardia72 closed 2 weeks ago
I need more information. You will need to add a new version entry to the migration document. You can't edit a version that has been applied. Is this what you mean?
Yes, that's what I mean We have two cases: 1- Adding a field to the table 2- Changing the type of that field If possible, write me an example here
You said here You will need to add a new version entry to the migration document. For example, if I want to edit a field, how should I do this? For example, I want to change the name of a field or its type @ardan-bkennedy
Occasionally you will make a mistake when writing a migration. If you have already run the migration then you cannot just edit the migration and run the migration again.you must add new version of the migration or rollback the old migration.
How should I do what you said? Do you have a test sample?
After that, this rollback method does not cause data loss
@himynamej
You would use an ALTER COLUMN command in a new version of the migration. Here is a good example
-- Version: 1.19
-- Description: Alter payments table.
ALTER TABLE payments ADD COLUMN gateway_status INT NULL;
ALTER TABLE payments ADD COLUMN gateway_description TEXT NULL;
ALTER TABLE payments ADD COLUMN failed BOOL NULL;
UPDATE payments SET failed = false WHERE status != 'failed';
UPDATE payments SET failed = true WHERE status = 'failed';
ALTER TABLE payments ALTER COLUMN failed SET NOT NULL;
tnx
Why, when we want to edit a field or change its type, the changes are not applied in the database with the migration command.