def generate_models(self, skip_invalid=False, table_names=None):
        database = self.introspect(table_names=table_names)
        models = {}

        class BaseModel(Model):
            class Meta:
                database = self.metadata.database

        def _create_model(table, models):
            for foreign_key in database.foreign_keys[table]:
                dest = foreign_key.dest_table

                if dest not in models and dest != table:
                    _create_model(dest, models)

            primary_keys = []
            columns = database.columns[table]
            for db_column, column in columns.items():
                if column.primary_key:
                    primary_keys.append(column.name)

            multi_column_indexes = database.multi_column_indexes(table)
            column_indexes = database.column_indexes(table)

            class Meta:
                indexes = multi_column_indexes

            # Fix models with multi-column primary keys.
            composite_key = False
            if len(primary_keys) == 0:
                primary_keys = columns.keys()
            if len(primary_keys) > 1:
                Meta.primary_key = CompositeKey(*[
                    field.name for col, field in columns.items()
                    if col in primary_keys])
                composite_key = True

            attrs = {'Meta': Meta}
            for db_column, column in columns.items():
                FieldClass = column.field_class
                if FieldClass is UnknownField:
                    FieldClass = BareField

                params = {
                    'db_column': db_column,
                    'null': column.nullable}
                if column.primary_key and composite_key:
                    if FieldClass is PrimaryKeyField:
                        FieldClass = IntegerField
                    params['primary_key'] = False
                elif column.primary_key and FieldClass is not PrimaryKeyField:
                    params['primary_key'] = True
                if column.is_foreign_key():
                    if column.is_self_referential_fk():
                        params['rel_model'] = 'self'
                    else:
                        dest_table = column.foreign_key.dest_table
                        params['rel_model'] = models[dest_table]
                    if column.to_field:
                        params['to_field'] = column.to_field

                    # Generate a unique related name.
                    params['related_name'] = '%s_%s_rel' % (table, db_column)
                if column_indexes in db_column and not column.is_primary_key():
                    if column_indexes[db_column]:
                        params['unique'] = True
                    elif not column.is_foreign_key():
                        params['index'] = True

                attrs[column.name] = FieldClass(**params)

            try:
                models[table] = type(str(table), (BaseModel,), attrs)
            except ValueError:
                if not skip_invalid:
                    raise

        # Actually generate Model classes.
        for table, model in sorted(database.model_names.items()):
            if table not in models:
                _create_model(table, models)

        return models
dataset/ETHPy150Open coleifer/peewee/playhouse/reflection.py/Introspector.generate_models/swapped operands of `in`