35330-vm/Backend/db/migrations/010_fix_budgets_unique_key.sql
Flatlogic Bot 6d3c0cd8d3 versao 18
2025-10-29 19:20:02 +00:00

10 lines
441 B
SQL

-- Drop the foreign key constraint first
ALTER TABLE `budgets` DROP FOREIGN KEY `budgets_ibfk_1`;
-- Now, drop the old unique key and add the new one
ALTER TABLE `budgets`
DROP KEY `user_category_month`,
ADD UNIQUE KEY `client_month_category` (`client_id`, `budget_month`, `category`);
-- Add the foreign key back
ALTER TABLE `budgets` ADD CONSTRAINT `fk_budgets_user_id` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE;