Opened 6 years ago
Closed 6 years ago
#31399 closed Bug (fixed)
SchemaEditor._alter_field() looks for foreign key constraints even if the database doesn't support them.
| Reported by: | Tim Graham | Owned by: | Tim Graham |
|---|---|---|---|
| Component: | Migrations | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
BaseDatabaseSchemaEditor._alter_field() 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.
Change History (4)
comment:1 by , 6 years ago
| Easy pickings: | set |
|---|---|
| Summary: | SchemaEditor._alter_field() looks for foreign key constraints even if the database doesn't support them → SchemaEditor._alter_field() looks for foreign key constraints even if the database doesn't support them. |
| Triage Stage: | Unreviewed → Accepted |
comment:3 by , 6 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
| Triage Stage: | Accepted → Ready for checkin |
Note:
See TracTickets
for help on using tickets.