#29182: SQLite database migration breaks ForeignKey constraint, leaving
<table_name>__old in db schema
----------------------------------+------------------------------------
Reporter: ezaquarii | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 2.1
Severity: Release blocker | Resolution:
Keywords: sqlite migration | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Comment (by Florian Apolloner):
Simon, the following test is the best I could come up with -- not sure if
there is a better way aside from querying `sqlite_master`, but seems to be
okay for the purpose of the test.
{{{
#!python
@isolate_apps('schema')
@unittest.skipUnless(connection.vendor == 'sqlite', 'SQLite naively
remakes the table on field alteration.')
def test_table_remake_with_fks_pointing_to_it(self):
class File(Model):
content = ForeignKey("FileContent", on_delete=PROTECT)
class Meta:
app_label = 'schema'
class FileContent(Model):
class Meta:
app_label = 'schema'
class PlayBook(Model):
file = ForeignKey("File", on_delete=PROTECT)
class Meta:
app_label = 'schema'
new_field = ForeignKey(FileContent, on_delete=PROTECT)
new_field.set_attributes_from_name("filecontent")
with connection.schema_editor(atomic=True) as editor:
editor.create_model(File)
editor.create_model(FileContent)
editor.create_model(PlayBook)
editor.add_field(File, new_field)
with connection.cursor() as cursor:
cursor.execute("SELECT sql FROM sqlite_master WHERE
type='table' and tbl_name='schema_playbook'")
result = cursor.fetchone()[0]
self.assertNotIn("__old", result)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29182#comment:19>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.a48486750403c09351929907d37951ca%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.