Table "fees": add missing foreign key on "account_row_id"
The MariaDB table fees is probably missing a foreign key.
Current definition:
CREATE TABLE `fees` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`account_row_id` int(10) unsigned DEFAULT NULL,
`user_id` int(10) unsigned NOT NULL,
`year` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `fees_user_id_foreign` (`user_id`),
CONSTRAINT `fees_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
Definition of the destination:
CREATE TABLE `account_rows` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`movement_id` int(10) unsigned DEFAULT NULL,
`account_id` int(10) unsigned NOT NULL,
`user_id` int(10) unsigned NOT NULL DEFAULT 0,
`section_id` int(10) unsigned NOT NULL DEFAULT 0,
`amount_in` decimal(10,2) NOT NULL DEFAULT 0.00,
`amount_out` decimal(10,2) NOT NULL DEFAULT 0.00,
`notes` text NOT NULL,
PRIMARY KEY (`id`),
KEY `account_rows_movement_id_foreign` (`movement_id`),
CONSTRAINT `account_rows_movement_id_foreign` FOREIGN KEY (`movement_id`) REFERENCES `movements` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
The table fees is probably missing a foreign key, like this one:
ALTER TABLE fees ADD CONSTRAINT `fees_account_row_id_foreign` FOREIGN KEY (`account_row_id`) REFERENCES `account_rows`(`id`);
Let's add a migration script to add that specific foreign key.
Migration scripts are here:
https://gitlab.com/ItalianLinuxSociety/ilsmanager/-/tree/master/database/migrations?ref_type=heads
Edited by Valerio Bozzolan