'Tests the AlterField operation on primary keys changes any FKs pointing to it.'

@skipUnlessDBFeature('supports_foreign_keys')
def test_alter_field_pk_fk(self):

    project_state = self.set_up_test_model('test_alflpkfk', related_model=True)
    operation = migrations.AlterField('Pony', 'id', models.FloatField(primary_key=True))
    new_state = project_state.clone()
    operation.state_forwards('test_alflpkfk', new_state)
    self.assertIsInstance(project_state.models[('test_alflpkfk', 'pony')].get_field_by_name('id'), models.AutoField)
    self.assertIsInstance(new_state.models[('test_alflpkfk', 'pony')].get_field_by_name('id'), models.FloatField)
    def assertIdTypeEqualsFkType():
        with connection.cursor() as cursor:
            (id_type, id_null) = [(c.type_code, c.null_ok) for c in connection.introspection.get_table_description(cursor, 'test_alflpkfk_pony') if (c.name == 'id')][0]
            (fk_type, fk_null) = [(c.type_code, c.null_ok) for c in connection.introspection.get_table_description(cursor, 'test_alflpkfk_rider') if (c.name == 'pony_id')][0]
        self.assertEqual(id_type, fk_type)
        self.assertEqual(id_null, fk_null)
    assertIdTypeEqualsFkType()
    with connection.schema_editor() as editor:
        operation.database_forwards('test_alflpkfk', editor, project_state, new_state)
    assertIdTypeEqualsFkType()
    with connection.schema_editor() as editor:
        operation.database_backwards('test_alflpkfk', editor, new_state, project_state)
    assertIdTypeEqualsFkType()
