#24300: FK from `unmigrated` app model to `migrated` app model is not created
----------------------------+--------------------
     Reporter:  sir-sigurd  |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Migrations  |    Version:  1.7
     Severity:  Normal      |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+--------------------
 `foo/models.py`

 {{{
 from django.db import models

 from bar.models import Bar

 class Foo(models.Model):

     bar = models.ForeignKey(Bar)
 }}}

 `bar/models.py`

 {{{
 from django.db import models

 class Bar(models.Model):

     baz = models.IntegerField()
 }}}

 do `./manage.py migrate`

 {{{
 Operations to perform:
   Synchronize unmigrated apps: foo
   Apply all migrations: bar
 Synchronizing apps without migrations:
   Creating tables...
     Creating table foo_foo
   Installing custom SQL...
   Installing indexes...
 Running migrations:
   Applying bar.0001_initial... OK
 }}}

 do `psql -c '\d foo_foo' test_django`

 {{{
                         Table "public.foo_foo"
  Column |  Type   |                      Modifiers
 --------+---------+------------------------------------------------------
  id     | integer | not null default nextval('foo_foo_id_seq'::regclass)
  bar_id | integer | not null
 Indexes:
     "foo_foo_pkey" PRIMARY KEY, btree (id)
     "foo_foo_bar_id" btree (bar_id)
 }}}

 FK is absent.

 On 1.8a1 `migrate` step throws this error:

 {{{
 Operations to perform:
   Synchronize unmigrated apps: foo
   Apply all migrations: bar
 Synchronizing apps without migrations:
   Creating tables...
     Creating table foo_foo
     Running deferred SQL...
 Traceback (most recent call last):
   File "./manage.py", line 10, in <module>
     execute_from_command_line(sys.argv)
   File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-
 packages/django/core/management/__init__.py", line 338, in
 execute_from_command_line
     utility.execute()
   File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-
 packages/django/core/management/__init__.py", line 330, in execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-
 packages/django/core/management/base.py", line 390, in run_from_argv
     self.execute(*args, **cmd_options)
   File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-
 packages/django/core/management/base.py", line 441, in execute
     output = self.handle(*args, **options)
   File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-
 packages/django/core/management/commands/migrate.py", line 173, in handle
     created_models = self.sync_apps(connection,
 executor.loader.unmigrated_apps)
   File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-
 packages/django/core/management/commands/migrate.py", line 309, in
 sync_apps
     cursor.execute(statement)
   File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-
 packages/django/db/backends/utils.py", line 80, in execute
     return super(CursorDebugWrapper, self).execute(sql, params)
   File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-
 packages/django/db/backends/utils.py", line 65, in execute
     return self.cursor.execute(sql, params)
   File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-
 packages/django/db/utils.py", line 95, in __exit__
     six.reraise(dj_exc_type, dj_exc_value, traceback)
   File "/home/sergey/tmp/django-fk/local/lib/python2.7/site-
 packages/django/db/backends/utils.py", line 63, in execute
     return self.cursor.execute(sql)
 django.db.utils.ProgrammingError: relation "bar_bar" does not exist
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24300>
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/053.b5c140a717daf2219831b0014dffd5c1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to