﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30409	"E012 is raised when ForeignKey is used by ""_id"" in an Index."	James Cheese	zeynel	"Looks to be an issue with the implementation in #28714 - issue found whilst upgrading from 2.0 to 2.2, but also occurs in latest 2.1.x.

To duplicate, create a compound index including the ID for a ForeignKey, eg:

{{{#!python

class DataConcentrator(models.Model):
    #...

class ConcentratorHeartbeat(models.Model):
    #...
    class Meta:
        indexes = [
            models.Index(fields=[""source_id"", ""-collected_at""]),
        ]
    #...
    source = models.ForeignKey(DataConcentrator, null=True, related_name=""heartbeats"", on_delete=models.CASCADE)
}}}

Expected behaviour:
No errors raised

Encountered behaviour:
Error raised on system check:

{{{
Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x00000298392F3D08>
Traceback (most recent call last):
  File ""C:\Workspace\sensor-analytics-tool\.pyenv\lib\site-packages\django\utils\autoreload.py"", line 225, in wrapper
    fn(*args, **kwargs)
  File ""C:\Workspace\sensor-analytics-tool\.pyenv\lib\site-packages\django\core\management\commands\runserver.py"", line 117, in inner_run
    self.check(display_num_errors=True)
  File ""C:\Workspace\sensor-analytics-tool\.pyenv\lib\site-packages\django\core\management\base.py"", line 425, in check
    raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:
sensor_receiver.ConcentratorHeartbeat: (models.E012) 'indexes' refers to the nonexistent field 'source_id'.

System check identified 2 issues (0 silenced).
}}}

Current workaround is to just silence E012. Gets things running, but obviously not ideal."	Cleanup/optimization	closed	Core (System checks)	dev	Normal	fixed			Accepted	1	0	0	0	0	0
