'Creates a test model state and database table.'

def set_up_test_model(self, app_label, second_model=False, third_model=False, index=False, multicol_index=False, related_model=False, mti_model=False, proxy_model=False, manager_model=False, unique_together=False, options=False, db_table=None, index_together=False):

    table_names = ['_pony_stables', '_pony_vans', '_pony', '_stable', '_van']
    tables = [(app_label + table_name) for table_name in table_names]
    with connection.cursor() as cursor:
        table_names = connection.introspection.table_names(cursor)
        connection.disable_constraint_checking()
        sql_delete_table = connection.schema_editor().sql_delete_table
        with transaction.atomic():
            for table in tables:
                if (table in table_names):
                    cursor.execute((sql_delete_table % {'table': connection.ops.quote_name(table)}))
        connection.enable_constraint_checking()
    model_options = {'swappable': 'TEST_SWAP_MODEL', 'index_together': ([['weight', 'pink']] if index_together else []), 'unique_together': ([['pink', 'weight']] if unique_together else [])}
    if options:
        model_options['permissions'] = [('can_groom', 'Can    groom')]
    if db_table:
        model_options['db_table'] = db_table
    operations = [migrations.CreateModel('Pony', [('id', models.AutoField(primary_key=True)), ('pink', models.IntegerField(default=3)), ('weight', models.FloatField())], options=model_options)]
    if index:
        operations.append(migrations.AddIndex('Pony', models.Index(fields=['pink'], name='pony_pink_idx')))
    if multicol_index:
        operations.append(migrations.AddIndex('Pony', models.Index(fields=['pink', 'weight'], name='pony_test_idx')))
    if second_model:
        operations.append(migrations.CreateModel('Stable', [('id', models.AutoField(primary_key=True))]))
    if third_model:
        operations.append(migrations.CreateModel('Van', [('id', models.AutoField(primary_key=True))]))
    if related_model:
        operations.append(migrations.CreateModel('Rider', [('id', models.AutoField(primary_key=True)), ('pony', models.ForeignKey('Pony', models.CASCADE)), ('friend', models.ForeignKey('self', models.CASCADE))]))
    if mti_model:
        operations.append(migrations.CreateModel('ShetlandPony', fields=[('pony_ptr', models.OneToOneField('Pony', models.CASCADE, auto_created=True, parent_link=True, primary_key=True, to_field='id', serialize=False)), ('cuteness', models.IntegerField(default=1))], bases=[('%s.Pony' % app_label)]))
    if proxy_model:
        operations.append(migrations.CreateModel('ProxyPony', fields=[], options={'proxy': True}, bases=[('%s.Pony' % app_label)]))
    if manager_model:
        operations.append(migrations.CreateModel('Food', fields=[('id', models.AutoField(primary_key=True))], managers=[('food_qs', FoodQuerySet.as_manager()), ('food_mgr', FoodManager('a', 'b')), ('food_mgr_kwargs', FoodManager('x', 'y', 3, 4))]))
    return self.apply_operations(app_label, ProjectState(), operations)
