Hi ! I have identified very reproducible steps (cf attached file).
It fails with a single app with a single model with single field which is a foreign key to ContentType. Testable instantly with tox : - install django and tox in your prefered env - run steps.sh wichi will create all files. - configure the settings (postgresql, db name, password, ..), add the "example" app to the INSTALLED_APPS - run tox from the "fkregression" folder I coded a test that checks for the actual foreign keys in the system table of PostgreSQL, looking for multiple foreign keys. It passes on django 1.5 and 1.6, but fails with django 1.7 I will fill a bug with similar info. NotSqrt Le mercredi 29 octobre 2014 22:37:05 UTC+1, Carl Meyer a écrit : > > Hi NotSqrt, > > On 10/29/2014 11:53 AM, not...@gmail.com <javascript:> wrote: > > Just tested the following: > > > > * create clean DB > > * run syncdb > > * compare obtained tables when using Django 1.6.8 and Django 1.7.1 > > > > My findings : > > > > In Django 1.7, some fields with models.ForeignKey no longer get the DB > > constraint. > > > > In Django 1.6, I indeed get (in postgresql) for instance: > > CONSTRAINT TABLE_FIELD_id_fkey FOREIGN KEY (FIELD_id) > > REFERENCES django_content_type (id) MATCH SIMPLE > > ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY > > DEFERRED, > > > > The models for which it fails are always: > > > > * ContentType > > * Auth.Group > > * Auth.permission > > * django_site > > > > My local apps are always defined after "django.contrib.contenttypes" and > > "django.contrib.auth" in INSTALLED_APPS. > > Putting "django.contrib.contenttypes" as my last app does not change the > > DB construction. > > > > So does it have to do with the order in INSTALLED_APPS ? > > Is it a regression ? > > I don't have time to look into this and try to reproduce at the moment, > but if the situation is as you've described it (and it's not due to > something else specific to your project), it is certainly a regression > and a bug. If you can reproduce with a fixed set of steps (starting from > a fresh "startproject" for each Django version), please do file a bug at > code.djangoproject.com with those reproduction instructions. Thanks! > > Carl > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d957d88e-b590-481e-b588-76391cb33bbd%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
django-admin startproject fkregression cd fkregression/ ./manage.py startapp example rm -rf example/migrations example/admin.py example/views.py cat >example/models.py <<'EOT' from django.contrib.contenttypes.models import ContentType from django.db import models class MyModel(models.Model): content_type = models.ForeignKey(ContentType, verbose_name="Content type of Object") EOT cat >example/tests.py <<'EOT' from django.test import TestCase from django.contrib.contenttypes.models import ContentType from django.contrib.admin.models import LogEntry from django.contrib.auth.models import Permission from django.db import connection from example.models import MyModel # query that returns tuples (foreign key column, source table, foreign table) LIST_FOREIGN_KEY_QUERY = """SELECT pg_attribute.attname AS column, source_table.relname AS source_table, foreign_table.relname AS foreign_table FROM pg_constraint INNER JOIN pg_class as foreign_table ON confrelid = foreign_table.oid INNER JOIN pg_class as source_table ON conrelid = source_table.oid INNER JOIN pg_attribute ON pg_constraint.conkey @> ARRAY[pg_attribute.attnum] AND pg_attribute.attrelid = source_table.oid WHERE contype = 'f' -- limit to foreign keys """ class TestFK(TestCase): def test_connection(self): cursor = connection.cursor() cursor.execute('SELECT current_database()') self.assertEqual(cursor.fetchone()[0], 'test_test_fk') cursor.execute(LIST_FOREIGN_KEY_QUERY) foreign_keys = set(cursor) some_expected_foreign_keys = { ("content_type_id", Permission._meta.db_table, ContentType._meta.db_table), ("content_type_id", LogEntry._meta.db_table, ContentType._meta.db_table), } self.assertLess(some_expected_foreign_keys, foreign_keys) self.assertIn( ("content_type_id", MyModel._meta.db_table, ContentType._meta.db_table), foreign_keys ) EOT echo "add 'example' to INSTALLED_APPS" echo "configure DB." # I use ## DATABASES = { ## 'default': { ## 'ENGINE': 'django.db.backends.postgresql_psycopg2', ## 'NAME': 'test_fk', ## 'USER': '********', ## 'PASSWORD': '**********', ## 'HOST': '', ## 'PORT': '5433', ## } ## } cat >tox.ini <<'EOT' # To use this, "pip install tox" # and then run "tox" from this directory. [tox] minversion=1.8.0 skipsdist=true envlist = py27-django15, py27-django16, py27-django17, [testenv] commands = python manage.py test example deps = psycopg2 django15: django >=1.5,<1.6 django16: django >=1.6,<1.7 django17: django >=1.7,<1.8 EOT echo "run 'tox'"