upgrade 6.2 to 6.4 error - Cannot invoke "Object.getClass()" because "object" is null

Henry6 months ago

I Need some help with the following.
Running debian 12 on proxmox with traccar in a docker with my mariadb also in a docker, and I tried a few times to upgrade to 6.4 but my h02 devices and gt06 device stay offline, run the following sql to check the big tables for errors

SELECT COUNT(*) FROM traccar.tc_positions WHERE deviceid NOT IN (SELECT id FROM traccar.tc_devices);
count = 0
SELECT COUNT(*) FROM traccar.tc_events WHERE deviceid NOT IN (SELECT id FROM traccar.tc_devices);  
count=0

I get the following in the log file.

2024-08-15 17:37:28  INFO: Starting server...
2024-08-15 17:37:28  INFO: HikariPool-1 - Starting...
2024-08-15 17:37:29  INFO: HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@7bdf6bb7
2024-08-15 17:37:29  INFO: HikariPool-1 - Start completed.
2024-08-15 17:37:29  INFO: Error fetching reserved words list from JDBC driver - Unknown column 'RESERVED' in 'where clause' - SQLSyntaxErrorException (... < DatabaseModule:90 < <gener:-1 < *:-1 < ... < MainModule:129 < <gener:-1 < ...)
2024-08-15 17:37:29  INFO: Clearing database change log checksums
2024-08-15 17:37:29  INFO: Successfully acquired change log lock
2024-08-15 17:37:30  INFO: Successfully released change log lock
2024-08-15 17:37:34  INFO: Reading from traccar.DATABASECHANGELOG
2024-08-15 17:37:36  INFO: Reading from traccar.DATABASECHANGELOG
2024-08-15 17:37:36  INFO: Reading from traccar.DATABASECHANGELOG
2024-08-15 17:37:36  INFO: UPDATE SUMMARY
2024-08-15 17:37:36  INFO: Run:                          0
2024-08-15 17:37:36  INFO: Previously run:              49
2024-08-15 17:37:36  INFO: Filtered out:                 0
2024-08-15 17:37:36  INFO: -------------------------------
2024-08-15 17:37:36  INFO: Total change sets:           49

2024-08-15 17:37:36  INFO: Update summary generated
2024-08-15 17:37:36  INFO: Successfully released change log lock
2024-08-15 17:37:36  INFO: Command execution complete
2024-08-15 17:37:36  WARN: No systemd support - Unable to load library 'systemd':
Error loading shared library libsystemd.so: No such file or directory
Error loading shared library libsystemd.so: No such file or directory
Native library (linux-x86-64/libsystemd.so) not found in resource path (tracker-server.jar) - UnsatisfiedLinkError (... < TaskHealthCheck:59 < <gener:-1 < *:-1 < ... < ScheduleManager:55 < ... < *:54 < Main:126 < ...)
2024-08-15 17:37:38  INFO: jetty-11.0.21; built: 2024-05-14T03:19:28.958Z; git: 996cd61addad9cb033e0e3eba6fa3f0fa3dc270d; jvm 17.0.12+7-alpine-r0
2024-08-15 17:37:38  INFO: Started o.t.w.@36afb791{/,null,AVAILABLE}
2024-08-15 17:37:38  INFO: Session workerName=node0
2024-08-15 17:37:39  WARN: JAXBContext implementation could not be found. WADL feature is disabled.
2024-08-15 17:37:40  INFO: Started o.e.j.s.ServletContextHandler@7a06cd36{/,null,AVAILABLE}
2024-08-15 17:37:40  INFO: Started ServerConnector@49dc2e08{HTTP/1.1, (http/1.1)}{0.0.0.0:8082}
2024-08-15 17:37:40  INFO: Started Server@8c7e3c1{STARTING}[11.0.21,sto=0] @13909ms
2024-08-15 17:37:44  INFO: user: 1, action: login, from: 192.168.65.79
2024-08-15 17:37:48  INFO: [Td4ed30a4] connected
2024-08-15 17:37:48  INFO: [Td4ed30a4: gt06 < 41.4.25.237] 78780d010355488020955161049096a20d0a
2024-08-15 17:37:48  INFO: [Td4ed30a4] error - Cannot invoke "Object.getClass()" because "object" is null - NullPointerException (CacheKey:22 < CacheGraph:95 < CacheManager:291 < *:303 < *:292 < *:317 < *:164 < ConnectionManager:157 < ...)
2024-08-15 17:37:48  INFO: [Td4ed30a4] disconnected
2024-08-15 17:38:19  INFO: [T26942444] connected
2024-08-15 17:38:19  INFO: [T26942444: gt06 < 41.4.11.2] 78780d0103554880209551610491872b0d0a
2024-08-15 17:38:19  INFO: [T26942444] error - Cannot invoke "Object.getClass()" because "object" is null - NullPointerException (CacheKey:22 < CacheGraph:95 < CacheManager:291 < *:325 < *:164 < ConnectionManager:157 < ...)
2024-08-15 17:38:19  INFO: [T26942444] disconnected
2024-08-15 17:38:23  INFO: [Ta64fcc27] connected
2024-08-15 17:38:23  INFO: [Ta64fcc27: gt06 < 41.4.9.199] 78780d010355488020850718000415650d0a
2024-08-15 17:38:23  INFO: [Ta64fcc27] error - Cannot invoke "Object.getClass()" because "object" is null - NullPointerException (CacheKey:22 < CacheGraph:95 < CacheManager:291 < *:325 < *:164 < ConnectionManager:157 < ...)
2024-08-15 17:38:23  INFO: [Ta64fcc27] disconnected
2024-08-15 17:38:35  INFO: user: 1, action: login, from: 192.168.65.202
2024-08-15 17:38:52  INFO: [Td8cff374] connected
2024-08-15 17:38:52  INFO: [Td8cff374: gt06 < 41.4.9.42] 78780d010355488020850718000504ec0d0a
2024-08-15 17:38:52  INFO: [Td8cff374] error - Cannot invoke "Object.getClass()" because "object" is null - NullPointerException (CacheKey:22 < CacheGraph:95 < CacheManager:291 < *:325 < *:164 < ConnectionManager:157 < ...)
2024-08-15 17:38:52  INFO: [Td8cff374] disconnected
2024-08-15 17:38:59  INFO: [T0a2c59c8] connected
2024-08-15 17:38:59  INFO: [T0a2c59c8: gt06 < 41.4.21.166] 78780d0103554880209551610493a4390d0a
2024-08-15 17:38:59  INFO: [T0a2c59c8] error - Cannot invoke "Object.getClass()" because "object" is null - NullPointerException (CacheKey:22 < CacheGraph:95 < CacheManager:291 < *:325 < *:164 < ConnectionManager:157 < ...)
2024-08-15 17:38:59  INFO: [T0a2c59c8] disconnected
2024-08-15 17:39:17  INFO: [T7bb7764d] connected
2024-08-15 17:39:17  INFO: [T7bb7764d: gt06 < 105.245.52.164] 78780d0103554880209551610494d0860d0a
2024-08-15 17:39:17  INFO: [T7bb7764d] error - Cannot invoke "Object.getClass()" because "object" is null - NullPointerException (CacheKey:22 < CacheGraph:95 < CacheManager:291 < *:325 < *:164 < ConnectionManager:157 < ...)
2024-08-15 17:39:17  INFO: [T7bb7764d] disconnected
2024-08-15 17:39:21  INFO: [Td6124bd4] connected
2024-08-15 17:39:21  INFO: [Td6124bd4: gt06 < 41.4.14.54] 78780d010355488020850718000636770d0a
2024-08-15 17:39:21  INFO: [Td6124bd4] error - Cannot invoke "Object.getClass()" because "object" is null - NullPointerException (CacheKey:22 < CacheGraph:95 < CacheManager:291 < *:325 < *:164 < ConnectionManager:157 < ...)
2024-08-15 17:39:21  INFO: [Td6124bd4] disconnected
2024-08-15 17:39:25  INFO: [Ta8164353] connected
2024-08-15 17:39:25  INFO: [Ta8164353: h02 < 105.245.56.251] *HQ,7201110376,V1,173925,A,2908.7501,S,02609.5891,E,000.00,000,150824,FFFFFBFF,655,01,0,0,6#
2024-08-15 17:39:25  INFO: [Ta8164353] error - Cannot invoke "Object.getClass()" because "object" is null - NullPointerException (CacheKey:22 < CacheGraph:95 < CacheManager:291 < *:325 < *:164 < ConnectionManager:157 < ...)
2024-08-15 17:39:25  INFO: [Ta8164353] disconnected
2024-08-15 17:39:47  INFO: [T548b8687] connected 
Anton Tananaev6 months ago

It likely means corrupted database with some missing objects in the graph.

Henry6 months ago

Do you know what the table name is.
This is the list of my tables

+------------------------+
| Tables_in_traccar      |
+------------------------+
| DATABASECHANGELOG      |
| DATABASECHANGELOGLOCK  |
| tc_attributes          |
| tc_calendars           |
| tc_commands            |
| tc_commands_queue      |
| tc_device_attribute    |
| tc_device_command      |
| tc_device_driver       |
| tc_device_geofence     |
| tc_device_maintenance  |
| tc_device_notification |
| tc_device_order        |
| tc_device_report       |
| tc_devices             |
| tc_drivers             |
| tc_events              |
| tc_geofences           |
| tc_group_attribute     |
| tc_group_command       |
| tc_group_driver        |
| tc_group_geofence      |
| tc_group_maintenance   |
| tc_group_notification  |
| tc_group_order         |
| tc_group_report        |
| tc_groups              |
| tc_keystore            |
| tc_maintenances        |
| tc_notifications       |
| tc_orders              |
| tc_positions           |
| tc_reports             |
| tc_servers             |
| tc_statistics          |
| tc_user_attribute      |
| tc_user_calendar       |
| tc_user_command        |
| tc_user_device         |
| tc_user_driver         |
| tc_user_geofence       |
| tc_user_group          |
| tc_user_maintenance    |
| tc_user_notification   |
| tc_user_order          |
| tc_user_report         |
| tc_user_user           |
| tc_users               |
+------------------------+
Henry6 months ago

If I drop the database and create again db and then restart traccar the new tables will be created, can I then just do the sql insert command for my tc_devices, or what other tables must I restore. I just want my devices back.

Anton Tananaev6 months ago

You probably need more than just devices. At least you need to link those devices to your user account.

Henry6 months ago

Thanks Anton for the guidance, I see in my tc_device_notification the table notificationid point to id 6 and 7, but I only got in tc_notifications id 1 and 2. Does notificationid in all the other tables a reference to tc_notifications.id. This mean I can delete the row where notificationid not in tc_notifications.id ?

Anton Tananaev6 months ago

Yes. You also need to figure our how you end up with this situation. Make sure you have the relevant foreign key constraints.

ZuluBravo6 months ago

I am having the same issue. I checked and the pre-req FK's are gone the 6.3 DB update didn't complete.

changelog-5.11	author	changelog-5.11	2024-04-27 12:33:28	47	EXECUTED	9:f30849022d894f99ea42f93e69c00ed8	addColumn tableName=tc_users			4.23.2			4246402270
changelog-6.2	author	changelog-6.2	2024-08-30 11:18:44	48	EXECUTED	9:4afc10f18622be53ad650af7d23ca1e0	dropColumn columnName=twelvehourformat, tableName=tc_servers; dropColumn columnName=twelvehourformat, tableName=tc_users; addColumn tableName=tc_attributes			4.23.2			5041920917
changelog-6.3-old	author	changelog-6.3	2024-08-30 11:18:44	49	MARK_RAN		dropForeignKeyConstraint baseTableName=tc_events, constraintName=fk_event_deviceid; dropForeignKeyConstraint baseTableName=tc_positions, constraintName=fk_position_deviceid			4.23.2			5041920917
changelog-6.3-new	author	changelog-6.3	2024-08-30 11:18:44	50	MARK_RAN		dropForeignKeyConstraint baseTableName=tc_events, constraintName=fk_events_deviceid; dropForeignKeyConstraint baseTableName=tc_positions, constraintName=fk_positions_deviceid			4.23.2			5041920917 

Log

2024-08-30 11:18:36  INFO: Reading from traccar.DATABASECHANGELOG
2024-08-30 11:18:40  INFO: Reading from traccar.DATABASECHANGELOG
2024-08-30 11:18:40  INFO: Successfully acquired change log lock
2024-08-30 11:18:40  INFO: Using deploymentId: 5041920917
2024-08-30 11:18:40  INFO: Reading from traccar.DATABASECHANGELOG
2024-08-30 11:18:41  INFO: Column tc_servers.twelvehourformat dropped
2024-08-30 11:18:43  INFO: Column tc_users.twelvehourformat dropped
2024-08-30 11:18:44  INFO: Columns priority(INT) added to tc_attributes
2024-08-30 11:18:44  INFO: ChangeSet changelog-6.2::changelog-6.2::author ran successfully in 3177ms
2024-08-30 11:18:44  INFO: Marking ChangeSet: "changelog-6.3::changelog-6.3-old::author" as ran despite precondition failure due to onFail='MARK_RAN': 
          schema/changelog-master.xml : Foreign Key fk_event_deviceid does not exist

2024-08-30 11:18:44  INFO: Marking ChangeSet: "changelog-6.3::changelog-6.3-new::author" as ran despite precondition failure due to onFail='MARK_RAN': 
          schema/changelog-master.xml : Foreign Key fk_events_deviceid does not exist

2024-08-30 11:18:44  INFO: UPDATE SUMMARY
2024-08-30 11:18:44  INFO: Run:                          3
2024-08-30 11:18:44  INFO: Previously run:              46
2024-08-30 11:18:44  INFO: Filtered out:                 0
2024-08-30 11:18:44  INFO: -------------------------------
2024-08-30 11:18:44  INFO: Total change sets:           49

2024-08-30 11:18:44  INFO: Update summary generated
2024-08-30 11:18:44  INFO: Update command completed successfully.
2024-08-30 11:18:44  INFO: Successfully released change log lock
2024-08-30 11:18:44  INFO: Command execution complete
2024-08-30 11:18:44  INFO: Health check enabled with period 480000
2024-08-30 11:18:46  INFO: jetty-11.0.21; built: 2024-05-14T03:19:28.958Z; git: 996cd61addad9cb033e0e3eba6fa3f0fa3dc270d; jvm 21.0.4+7-LTS
2024-08-30 11:18:46  INFO: Started o.t.w.@3281c71e{/,null,AVAILABLE}
2024-08-30 11:18:46  INFO: Session workerName=node0
2024-08-30 11:18:46  WARN: JAXBContext implementation could not be found. WADL feature is disabled.
2024-08-30 11:18:46  INFO: Started o.e.j.s.ServletContextHandler@1b1d3bc4{/,null,AVAILABLE}
2024-08-30 11:18:46  INFO: Started ServerConnector@69cad103{HTTP/1.1, (http/1.1)}{0.0.0.0:8082}
2024-08-30 11:18:46  INFO: Started Server@4ddff4e0{STARTING}[11.0.21,sto=0] @14910ms
2024-08-30 11:40:16  INFO: [T587be9c1] connected
2024-08-30 11:40:16  INFO: [T587be9c1: osmand < 1.2.3.4] POST /?id=56887123×tamp=y&lat=x&lon=z&speed=0&bearing=0&altitude=1111&accuracy=111&batt=1 HTTP/1.1\r\nHost: a.b.c:5055\r\nConnection: keep-alive\r\nAccept: */*\r\nUser-Agent: TraccarClient/59 CFNetwork/1399 Darwin/22.1.0\r\nAccept-Language: en-US,en;q=0.9\r\nContent-Length: 0\r\nAccept-Encoding: gzip, deflate\r\n\r\n
2024-08-30 11:40:17  INFO: [T587be9c1] error - Cannot invoke "Object.getClass()" because "object" is null - NullPointerException (CacheKey:22 < CacheGraph:95 < CacheManager:291 < *:317 < *:164 < ConnectionManager:157 < ...)
2024-08-30 11:40:17  INFO: [T587be9c1] disconnected

Current table schema (which seems to match the completed update for both tc_events and tc_positions)

CREATE TABLE `tc_events` (
  `id` int NOT NULL AUTO_INCREMENT,
  `type` varchar(128) NOT NULL,
  `eventtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `deviceid` int DEFAULT NULL,
  `positionid` int DEFAULT NULL,
  `geofenceid` int DEFAULT NULL,
  `attributes` varchar(4000) DEFAULT NULL,
  `maintenanceid` int DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `event_deviceid_servertime` (`deviceid`,`eventtime`)
) ENGINE=InnoDB AUTO_INCREMENT=455786 DEFAULT CHARSET=latin1;
CREATE TABLE `tc_positions` (
  `id` int NOT NULL AUTO_INCREMENT,
  `protocol` varchar(128) DEFAULT NULL,
  `deviceid` int NOT NULL,
  `servertime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `devicetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `fixtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `valid` bit(1) NOT NULL,
  `latitude` double NOT NULL,
  `longitude` double NOT NULL,
  `altitude` float NOT NULL,
  `speed` float NOT NULL,
  `course` float NOT NULL,
  `address` varchar(512) DEFAULT NULL,
  `attributes` varchar(4000) DEFAULT NULL,
  `accuracy` double NOT NULL DEFAULT '0',
  `network` varchar(4000) DEFAULT NULL,
  `geofenceids` varchar(128) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `position_deviceid_fixtime` (`deviceid`,`fixtime`)
) ENGINE=InnoDB AUTO_INCREMENT=2403689 DEFAULT CHARSET=latin1;

I reverted to 6.2 for now. Not sure what to try next. Perhaps it's worth trying to pre-create the FK's to get the script to run and I am missing something?

Anton Tananaev6 months ago

You're mixing up unrelated foreign keys. The ones that were removed in 6.3 are not relevant to the problem.

ZuluBravo6 months ago

Ok. The log trace is not helping determine which FK's I need to look at other than the device table. Where should I start looking? or would it make more sense to dump tc_devices, tc_users and tc_positions and recreate the DB and then reinsert the data?

Anton Tananaev6 months ago

You should look at everything that's linked to the device.

ZuluBravo6 months ago

I checked all tables for FK's and the results seem unclear. Only FK's referencing device are the following:

CREATE TABLE `tc_device_order` (
  `deviceid` int NOT NULL,
  `orderid` int NOT NULL,
  KEY `fk_device_order_deviceid` (`deviceid`),
  KEY `fk_device_order_orderid` (`orderid`),
  CONSTRAINT `fk_device_order_deviceid` FOREIGN KEY (`deviceid`) REFERENCES `tc_devices` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_device_order_orderid` FOREIGN KEY (`orderid`) REFERENCES `tc_orders` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE `tc_device_report` (
  `deviceid` int NOT NULL,
  `reportid` int NOT NULL,
  KEY `fk_device_report_deviceid` (`deviceid`),
  KEY `fk_device_report_reportid` (`reportid`),
  CONSTRAINT `fk_device_report_deviceid` FOREIGN KEY (`deviceid`) REFERENCES `tc_devices` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_device_report_reportid` FOREIGN KEY (`reportid`) REFERENCES `tc_reports` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

These appear to be as required based on the schema logs. Am i missing something?

Anton Tananaev6 months ago

Yes, you're missing a lot of foreign keys. That would explain the issue.

ZuluBravo6 months ago

Indeed I was. I also had some stale devices and user id's which prevented FK creation until it was cleaned up. I was able to quickly look at the indexes which were created properly to see where a lot of the issues were. I suspect the 4.0 schema was never fully applied properly so this was a long standing problem that I didn't encounter due to not using a lot of the newer schema features. Thank you for the pointers!

ALTER TABLE `tc_device_notification` ADD CONSTRAINT `fk_device_notification_deviceid` FOREIGN KEY (`deviceid`) REFERENCES `tc_devices` (`id`);
ALTER TABLE `tc_device_notification` ADD CONSTRAINT `fk_device_notification_notificationid` FOREIGN KEY (`notificationid`) REFERENCES `tc_notifications` (`id`);

ALTER TABLE `tc_device_maintenance` ADD CONSTRAINT `fk_device_maintenance_deviceid` FOREIGN KEY (`deviceid`) REFERENCES `tc_devices` (`id`) ON delete cascade;
ALTER TABLE `tc_device_maintenance` ADD CONSTRAINT `fk_device_maintenance_maintenanceid` FOREIGN KEY (`maintenanceid`) REFERENCES `tc_maintenances` (`id`) ON delete cascade;

ALTER TABLE `tc_device_geofence` ADD CONSTRAINT `fk_device_geofence_deviceid` FOREIGN KEY (`deviceid`) REFERENCES `tc_devices` (`id`) ON delete cascade;
ALTER TABLE `tc_device_geofence` ADD CONSTRAINT `fk_device_geofence_geofenceid` FOREIGN KEY (`geofenceid`) REFERENCES `tc_geofences` (`id`) ON delete cascade;

ALTER TABLE `tc_device_driver`ADD CONSTRAINT `fk_device_driver_deviceid` FOREIGN KEY (`deviceid`) REFERENCES `tc_devices` (`id`) ON delete cascade;
ALTER TABLE `tc_device_driver` ADD CONSTRAINT `fk_device_driver_driverid` FOREIGN KEY (`driverid`) REFERENCES `tc_drivers` (`id`) ON delete cascade;

ALTER TABLE `tc_device_command`ADD CONSTRAINT `fk_device_command_deviceid` FOREIGN KEY (`deviceid`) REFERENCES `tc_devices` (`id`) ON delete cascade;
ALTER TABLE `tc_device_command` ADD CONSTRAINT `fk_device_command_commandid` FOREIGN KEY (`commandid`) REFERENCES `tc_commands` (`id`) ON delete cascade;

ALTER TABLE `tc_device_command`ADD CONSTRAINT `fk_device_command_deviceid` FOREIGN KEY (`deviceid`) REFERENCES `tc_devices` (`id`) ON delete cascade;
ALTER TABLE `tc_device_command` ADD CONSTRAINT `fk_device_command_commandid` FOREIGN KEY (`commandid`) REFERENCES `tc_commands` (`id`) ON delete cascade;

ALTER TABLE `tc_device_attribute`ADD CONSTRAINT `fk_device_attribute_deviceid` FOREIGN KEY (`deviceid`) REFERENCES `tc_devices` (`id`) ON delete cascade;
ALTER TABLE `tc_device_attribute` ADD CONSTRAINT `fk_device_attribute_attributeid` FOREIGN KEY (`attributeid`) REFERENCES `tc_attributes` (`id`) ON delete cascade;

ALTER TABLE `tc_group_attribute`ADD CONSTRAINT `fk_group_attribute_groupid` FOREIGN KEY (`groupid`) REFERENCES `tc_groups` (`id`) ON delete cascade;
ALTER TABLE `tc_group_attribute` ADD CONSTRAINT `fk_group_attribute_attributeid` FOREIGN KEY (`attributeid`) REFERENCES `tc_attributes` (`id`) ON delete cascade;

ALTER TABLE `tc_group_command`ADD CONSTRAINT `fk_group_command_groupid` FOREIGN KEY (`groupid`) REFERENCES `tc_groups` (`id`) ON delete cascade;
ALTER TABLE `tc_group_command` ADD CONSTRAINT `fk_group_command_commandid` FOREIGN KEY (`commandid`) REFERENCES `tc_commands` (`id`) ON delete cascade;

ALTER TABLE `tc_group_driver`ADD CONSTRAINT `fk_group_driver_groupid` FOREIGN KEY (`groupid`) REFERENCES `tc_groups` (`id`) ON delete cascade;
ALTER TABLE `tc_group_driver` ADD CONSTRAINT `fk_group_driver_driverid` FOREIGN KEY (`driverid`) REFERENCES `tc_drivers` (`id`) ON delete cascade;

ALTER TABLE `tc_group_geofence`ADD CONSTRAINT `fk_group_geofence_groupid` FOREIGN KEY (`groupid`) REFERENCES `tc_groups` (`id`) ON delete cascade;
ALTER TABLE `tc_group_geofence` ADD CONSTRAINT `fk_group_geofence_geofenceid` FOREIGN KEY (`geofenceid`) REFERENCES `tc_geofences` (`id`) ON delete cascade;

ALTER TABLE `tc_group_maintenance`ADD CONSTRAINT `fk_group_maintenance_groupid` FOREIGN KEY (`groupid`) REFERENCES `tc_groups` (`id`) ON delete cascade;
ALTER TABLE `tc_group_maintenance` ADD CONSTRAINT `fk_group_maintenance_maintenanceid` FOREIGN KEY (`maintenanceid`) REFERENCES `tc_maintenances` (`id`) ON delete cascade;

ALTER TABLE `tc_group_notification`ADD CONSTRAINT `fk_group_notification_groupid` FOREIGN KEY (`groupid`) REFERENCES `tc_groups` (`id`) ON delete cascade;
ALTER TABLE `tc_group_notification` ADD CONSTRAINT `fk_group_notification_notificationid` FOREIGN KEY (`notificationid`) REFERENCES `tc_notifications` (`id`) ON delete cascade;

ALTER TABLE `tc_groups` ADD CONSTRAINT `fk_groups_groupid` FOREIGN KEY (`groupid`) REFERENCES `tc_groups` (`id`) ON UPDATE RESTRICT;

ALTER TABLE `tc_user_attribute`ADD CONSTRAINT `fk_user_attribute_userid` FOREIGN KEY (`userid`) REFERENCES `tc_users` (`id`) ON delete cascade;
ALTER TABLE `tc_user_attribute` ADD CONSTRAINT `fk_user_attribute_attributeid` FOREIGN KEY (`attributeid`) REFERENCES `tc_attributes` (`id`) ON delete cascade;

ALTER TABLE `tc_user_calendar`ADD CONSTRAINT `fk_user_calendar_userid` FOREIGN KEY (`userid`) REFERENCES `tc_users` (`id`) ON delete cascade;
ALTER TABLE `tc_user_calendar` ADD CONSTRAINT `fk_user_calendar_calendarid` FOREIGN KEY (`calendarid`) REFERENCES `tc_calendars` (`id`) ON delete cascade;

ALTER TABLE `tc_user_command`ADD CONSTRAINT `fk_user_command_userid` FOREIGN KEY (`userid`) REFERENCES `tc_users` (`id`) ON delete cascade;
ALTER TABLE `tc_user_command` ADD CONSTRAINT `fk_user_command_commandid` FOREIGN KEY (`commandid`) REFERENCES `tc_commands` (`id`) ON delete cascade;

ALTER TABLE `tc_user_attribute`ADD CONSTRAINT `fk_user_attribute_userid` FOREIGN KEY (`userid`) REFERENCES `tc_users` (`id`) ON delete cascade;
ALTER TABLE `tc_user_attribute` ADD CONSTRAINT `fk_user_attribute_attributeid` FOREIGN KEY (`attributeid`) REFERENCES `tc_attributes` (`id`) ON delete cascade;

ALTER TABLE `tc_user_device`ADD CONSTRAINT `fk_user_device_userid` FOREIGN KEY (`userid`) REFERENCES `tc_users` (`id`) ON delete cascade;
ALTER TABLE `tc_user_device` ADD CONSTRAINT `fk_user_device_deviceid` FOREIGN KEY (`deviceid`) REFERENCES `tc_devices` (`id`) ON delete cascade;

ALTER TABLE `tc_user_driver`ADD CONSTRAINT `fk_user_driver_userid` FOREIGN KEY (`userid`) REFERENCES `tc_users` (`id`) ON delete cascade;
ALTER TABLE `tc_user_driver` ADD CONSTRAINT `fk_user_driver_driverid` FOREIGN KEY (`driverid`) REFERENCES `tc_drivers` (`id`) ON delete cascade;

ALTER TABLE `tc_user_geofence`ADD CONSTRAINT `fk_user_geofence_userid` FOREIGN KEY (`userid`) REFERENCES `tc_users` (`id`) ON delete cascade;
ALTER TABLE `tc_user_geofence` ADD CONSTRAINT `fk_user_geofence_geofenceid` FOREIGN KEY (`geofenceid`) REFERENCES `tc_geofences` (`id`) ON delete cascade;

ALTER TABLE `tc_user_group`ADD CONSTRAINT `fk_user_group_userid` FOREIGN KEY (`userid`) REFERENCES `tc_users` (`id`) ON delete cascade;
ALTER TABLE `tc_user_group` ADD CONSTRAINT `fk_user_group_groupid` FOREIGN KEY (`groupid`) REFERENCES `tc_groups` (`id`) ON delete cascade;

ALTER TABLE `tc_user_maintenance`ADD CONSTRAINT `fk_user_maintenance_userid` FOREIGN KEY (`userid`) REFERENCES `tc_users` (`id`) ON delete cascade;
ALTER TABLE `tc_user_maintenance` ADD CONSTRAINT `fk_user_maintenance_maintenanceid` FOREIGN KEY (`maintenanceid`) REFERENCES `tc_maintenances` (`id`) ON delete cascade;

ALTER TABLE `tc_user_notification`ADD CONSTRAINT `fk_user_notification_userid` FOREIGN KEY (`userid`) REFERENCES `tc_users` (`id`) ON delete cascade;
ALTER TABLE `tc_user_notification` ADD CONSTRAINT `fk_user_notification_notificationid` FOREIGN KEY (`notificationid`) REFERENCES `tc_notifications` (`id`) ON delete cascade;

ALTER TABLE `tc_user_order`ADD CONSTRAINT `fk_user_order_userid` FOREIGN KEY (`userid`) REFERENCES `tc_users` (`id`) ON delete cascade;
ALTER TABLE `tc_user_order` ADD CONSTRAINT `fk_user_order_orderid` FOREIGN KEY (`orderid`) REFERENCES `tc_orders` (`id`) ON delete cascade;

ALTER TABLE `tc_user_user` ADD CONSTRAINT `fk_user_user_userid` FOREIGN KEY (`userid`) REFERENCES `tc_users` (`id`) ON delete cascade;
Kalabinta month ago

I had the same issue, probably because I started with the H2 database in 2017, then ported it to MariaDB and later to PostgreSQL (PostGIS).

Thanks for the ALTER TABLE list!

It took some time to work through it, including dealing with completely missing tables, but my Traccar instance seems to be back up and running.