When I try to migrate, I’m getting the following errors:
[standard:public] === Starting migration
[standard:public] Operations to perform:
[standard:public] Apply all migrations: accounts, admin, assets, auth, companies, contenttypes, costs, customers, dispatchers, django_q, drivers, loads, sessions, subsidiaries, summary, trips
Traceback (most recent call last):
File "/Users/valeriu/Sites/FleetData/manage.py", line 22, in <module>
main()
File "/Users/valeriu/Sites/FleetData/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/valeriu/Sites/FleetData/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
utility.execute()
File "/Users/valeriu/Sites/FleetData/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/valeriu/Sites/FleetData/venv/lib/python3.10/site-packages/django/core/management/base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/valeriu/Sites/FleetData/venv/lib/python3.10/site-packages/django/core/management/base.py", line 458, in execute
output = self.handle(*args, **options)
File "/Users/valeriu/Sites/FleetData/venv/lib/python3.10/site-packages/django_tenants/management/commands/migrate_schemas.py", line 63, in handle
executor.run_migrations(tenants=[self.PUBLIC_SCHEMA_NAME])
File "/Users/valeriu/Sites/FleetData/venv/lib/python3.10/site-packages/django_tenants/migration_executors/standard.py", line 11, in run_migrations
run_migrations(self.args, self.options, self.codename, self.PUBLIC_SCHEMA_NAME)
File "/Users/valeriu/Sites/FleetData/venv/lib/python3.10/site-packages/django_tenants/migration_executors/base.py", line 59, in run_migrations
migrate_command_class(stdout=stdout, stderr=stderr).execute(*args, **options)
File "/Users/valeriu/Sites/FleetData/venv/lib/python3.10/site-packages/django/core/management/base.py", line 458, in execute
output = self.handle(*args, **options)
File "/Users/valeriu/Sites/FleetData/venv/lib/python3.10/site-packages/django/core/management/base.py", line 106, in wrapper
res = handle_func(*args, **kwargs)
File "/Users/valeriu/Sites/FleetData/venv/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 302, in handle
pre_migrate_apps = pre_migrate_state.apps
File "/Users/valeriu/Sites/FleetData/venv/lib/python3.10/site-packages/django/utils/functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/valeriu/Sites/FleetData/venv/lib/python3.10/site-packages/django/db/migrations/state.py", line 566, in apps
return StateApps(self.real_apps, self.models)
File "/Users/valeriu/Sites/FleetData/venv/lib/python3.10/site-packages/django/db/migrations/state.py", line 637, in __init__
raise ValueError("\n".join(error.msg for error in errors))
ValueError: The field assets.TruckToDriverAssignment.dispatcher was declared with a lazy reference to 'dispatchers.dispatcher', but app 'dispatchers' isn't installed.
The field drivers.Driver.dispatcher was declared with a lazy reference to 'dispatchers.dispatcher', but app 'dispatchers' isn't installed.
The field loads.Load.sales_agent was declared with a lazy reference to 'dispatchers.dispatcher', but app 'dispatchers' isn't installed.
The field trips.Trip.dispatcher was declared with a lazy reference to 'dispatchers.dispatcher', but app 'dispatchers' isn't installed.
class Driver(models.Model):
dispatcher = models.ForeignKey(Dispatcher, on_delete=models.DO_NOTHING, null=True, blank=True)
....
class TruckToDriverAssignment(models.Model):
dispatcher = models.ForeignKey(Dispatcher, on_delete=models.CASCADE, null=True, blank=True)
...
class Load(models.Model):
sales_agent = models.ForeignKey(Dispatcher, on_delete=models.DO_NOTHING, related_name='sales_agent_loads', blank=True, null=True)
....
class Trip(models.Model):
dispatcher = models.ForeignKey(Dispatcher, on_delete=models.CASCADE, null=True, blank=True)
All these migration problems started when I switched a ForeignKey model reference from one model to another (first added a new field with the new reference, then changed the data in the table, then removed the old field with the reference).
I can’t seem to find more info anywhere. Any help highly appreciated.