'A dependency to an app with existing migrations uses the
last migration of that app.'

@override_settings(MIGRATION_MODULES={'migrations': 'migrations.test_migrations'})
def test_last_dependency(self):

    loader = MigrationLoader(connection)
    before = self.make_project_state([])
    after = self.make_project_state([self.book_migrations_fk])
    after.real_apps = ['migrations']
    autodetector = MigrationAutodetector(before, after)
    changes = autodetector._detect_changes(graph=loader.graph)
    self.assertNumberMigrations(changes, 'otherapp', 1)
    self.assertOperationTypes(changes, 'otherapp', 0, ['CreateModel'])
    self.assertOperationAttributes(changes, 'otherapp', 0, 0, name='Book')
    self.assertMigrationDependencies(changes, 'otherapp', 0, [('migrations', '0002_second')])
