[Answer]-Updating MySQL Database with foreign keys and Django

1👍

Here’s how I’d solve this:

  • Remove vehicle.Locations (otherwise you’ve got a circular relationship between the two tables)
  • Add a timestamp field to location, which has the time at which the vehicle arrives at a particular location
  • Make sure you always insert an entry into vehicle before referencing it in location

To find a vehicle’s current location, do a GROUP BY search on vehicle.VehId, and pick the one which has the greatest timestamp less than the current time.

Leave a comment