#19676: Inspectdb ForeignKey for self -------------------------------------+------------------------------------- Reporter: Georgy Kutsurua | Owner: charettes Type: Bug | Status: assigned Component: Uncategorized | Version: master Severity: Normal | Resolution: Keywords: inspectdb | Triage Stage: Accepted foreignkey | Needs documentation: 0 Has patch: 1 | Patch needs improvement: 0 Needs tests: 0 | UI/UX: 0 Easy pickings: 0 | -------------------------------------+-------------------------------------
Comment (by aaugustin): Although the patch looks good, the test fails on SQLite for me — the FK isn't detected and the output contains `parent_id = models.IntegerField()`. {{{ (django-dev)myk@mYk tests % PYTHONPATH=.. python runtests.py --settings=test_sqlite inspectdb Creating test database for alias 'default'... Creating test database for alias 'other'... F... ====================================================================== FAIL: test_attribute_name_not_python_keyword (regressiontests.inspectdb.tests.InspectDBTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/myk/Documents/dev/django/django/test/testcases.py", line 873, in skip_wrapper return test_func(*args, **kwargs) File "/Users/myk/Documents/dev/django/tests/regressiontests/inspectdb/tests.py", line 35, in test_attribute_name_not_python_keyword self.assertIn("parent = models.ForeignKey('self')", output) AssertionError: u"parent = models.ForeignKey('self')" not found in "# This is an auto-generated Django model module.\n# You'll have to do the following manually to clean this up:\n# * Rearrange models' order\n# * Make sure each model has one field with primary_key=True\n# Feel free to rename the models, but don't rename db_table values or field names.\n#\n# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [appname]'\n# into your database.\nfrom __future__ import unicode_literals\n\nfrom django.db import models\n\nclass InspectdbDigitsincolumnname(models.Model):\n id = models.IntegerField(primary_key=True)\n number_123 = models.CharField(max_length=11, db_column='123') # Field renamed because it wasn't a valid Python identifier.\n number_4extra = models.CharField(max_length=11, db_column='4extra') # Field renamed because it wasn't a valid Python identifier.\n number_45extra = models.CharField(max_length=11, db_column='45extra') # Field renamed because it wasn't a valid Python identifier.\n class Meta:\n db_table = 'inspectdb_digitsincolumnname'\n\nclass InspectdbMessage(models.Model):\n id = models.IntegerField(primary_key=True)\n from_field = models.ForeignKey('InspectdbPeople', db_column='from_id') # Field renamed because it was a Python reserved word.\n class Meta:\n db_table = 'inspectdb_message'\n\nclass InspectdbPeople(models.Model):\n id = models.IntegerField(primary_key=True)\n name = models.CharField(max_length=255)\n parent_id = models.IntegerField()\n class Meta:\n db_table = 'inspectdb_people'\n\nclass InspectdbPeopledata(models.Model):\n people_pk = models.ForeignKey(InspectdbPeople, primary_key=True)\n ssn = models.CharField(max_length=11)\n class Meta:\n db_table = 'inspectdb_peopledata'\n\nclass InspectdbPeoplemoredata(models.Model):\n id = models.IntegerField(primary_key=True)\n people_unique = models.ForeignKey(InspectdbPeople, unique=True)\n license = models.CharField(max_length=255)\n class Meta:\n db_table = 'inspectdb_peoplemoredata'\n\nclass InspectdbSpecialcolumnname(models.Model):\n id = models.IntegerField(primary_key=True)\n field = models.IntegerField()\n field_field = models.IntegerField(db_column='Field_') # Field name made lowercase. Field renamed because it ended with '_'.\n field_field_0 = models.IntegerField(db_column='Field__') # Field name made lowercase. Field renamed because it contained more than one '_' in a row. Field renamed because it ended with '_'. Field renamed because of name conflict.\n field_field_1 = models.IntegerField(db_column='__field') # Field renamed because it contained more than one '_' in a row. Field renamed because it started with '_'. Field renamed because of name conflict.\n prc_x = models.IntegerField(db_column='prc(%) x') # Field renamed to remove unsuitable characters.\n class Meta:\n db_table = 'inspectdb_specialcolumnname'\n\n" ---------------------------------------------------------------------- Ran 4 tests in 0.021s FAILED (failures=1) Destroying test database for alias 'default'... Destroying test database for alias 'other'... }}} -- Ticket URL: <https://code.djangoproject.com/ticket/19676#comment:7> 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 post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.