#31399: SchemaEditor._alter_field() looks for foreign key constraints even if 
the
database doesn't support them
--------------------------------------+------------------------
               Reporter:  Tim Graham  |          Owner:  nobody
                   Type:  Bug         |         Status:  new
              Component:  Migrations  |        Version:  master
               Severity:  Normal      |       Keywords:
           Triage Stage:  Unreviewed  |      Has patch:  0
    Needs documentation:  0           |    Needs tests:  0
Patch needs improvement:  0           |  Easy pickings:  0
                  UI/UX:  0           |
--------------------------------------+------------------------
 `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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31399>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.69a482ab44987ef9bd144bfc0988aac8%40djangoproject.com.

Reply via email to