﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24300	FK from `unmigrated` app model to `migrated` app model is not created	Sergey Fedoseev	nobody	"`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
}}}
"	Bug	closed	Migrations	1.7	Normal	invalid			Unreviewed	0	0	0	0	0	0
