﻿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
31399	SchemaEditor._alter_field() looks for foreign key constraints even if the database doesn't support them.	Tim Graham	Tim Graham	"`BaseDatabaseSchemaEditor._alter_field()` [https://github.com/django/django/blob/895f28f9cbed817c00ab68770433170d83132d90/django/db/backends/base/schema.py#L572-L582 does a lookup for foreign key constraints] even if the database doesn't support them, resulting in test failures like this:
{{{
======================================================================
ERROR: test_alter_field_fk_keeps_index (schema.tests.SchemaTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/home/tim/code/django/tests/schema/tests.py"", line 990, in test_alter_field_fk_keeps_index
    editor.alter_field(Book, old_field, new_field, strict=True)
  File ""/home/tim/code/django/django/db/backends/base/schema.py"", line 535, in alter_field
    old_db_params, new_db_params, strict)
  File ""/home/tim/code/django/django/db/backends/base/schema.py"", line 548, in _alter_field
    old_field.column,
ValueError: Found wrong number (0) of foreign key constraints for schema_book.author_id
}}}
This is a problem only when the argument `strict=True` is used (which I believe is only in tests).

To fix this, `self.connection.features.supports_foreign_keys` should be consulted.
"	Bug	closed	Migrations	dev	Normal	fixed			Ready for checkin	1	0	0	0	1	0
