private void foreignKeys(Connection conn, Table table) {
        requireNonNulls(conn, table);

        final Schema schema = table.getParentOrThrow();
        final SqlSupplier<ResultSet> supplier = () ->
            conn.getMetaData().getImportedKeys(null, null, table.getId());

        final Set<String> fksThatNeedNewNames = new LinkedHashSet<>();

        final TableChildMutator<ForeignKey> mutator = (foreignKey, rs) -> {

            final String foreignKeyName = rs.getString("FK_NAME");
            if (foreignKeyName == null || foreignKeyName.trim().isEmpty()) {
                if (rs.getInt(KEY_SEQ) == 1) {
                    final String uniqueName = UUID.randomUUID().toString();
                    foreignKey.mutator().setId(uniqueName);
                    foreignKey.mutator().setName(uniqueName);
                    fksThatNeedNewNames.add(uniqueName);
                }
            } else {
                foreignKey.mutator().setId(foreignKeyName);
                foreignKey.mutator().setName(foreignKeyName);
            }

            final ForeignKeyColumn foreignKeyColumn = foreignKey.mutator().addNewForeignKeyColumn();
            final ForeignKeyColumnMutator<?> fkcMutator = foreignKeyColumn.mutator();
            final String fkColumnName = rs.getString("FK" + COLUMN_NAME);
            fkcMutator.setId(fkColumnName);
            fkcMutator.setName(fkColumnName);
            fkcMutator.setOrdinalPosition(rs.getInt(KEY_SEQ));
            fkcMutator.setForeignTableName(rs.getString("PKTABLE_NAME"));
            fkcMutator.setForeignColumnName(rs.getString("PK" + COLUMN_NAME));

            // FKs always point to the same DBMS but can
            // be changed to another one using the config
            fkcMutator.setForeignDatabaseName(schema.getParentOrThrow().getId());
            fkcMutator.setForeignSchemaName(SCHEMA);
        };

        tableChilds(
            table,
            ForeignKey.class,
            table.mutator()::addNewForeignKey,
            supplier,
            rsChild -> rsChild.getInt(KEY_SEQ) == 1 ? ""
                : fksThatNeedNewNames.stream()
                    .skip(fksThatNeedNewNames.size() - 1L)
                    .findFirst().orElseThrow(IllegalStateException::new),
            mutator
        );

        // Fix foreign keys without any id by finding an index with the same
        // set of columns.
        table.foreignKeys()
            .filter(fk -> fksThatNeedNewNames.contains(fk.getId()))
            .forEach(fk -> {
                final Set<String> thisSet = fk.foreignKeyColumns()
                    .map(ForeignKeyColumn::getId)
                    .collect(toSet());

                final Optional<? extends Index> found = table.indexes()
                    .filter(idx -> idx.indexColumns()
                        .map(IndexColumn::getId)
                        .collect(toSet())
                        .equals(thisSet)
                    ).findFirst();

                if (found.isPresent()) {
                    fk.mutator().setId(found.get().getId());
                    fk.mutator().setName(found.get().getName());
                } else {
                    final String randName = md5(thisSet.toString());
                    fk.mutator().setId(randName);
                    fk.mutator().setName(randName);
                    LOGGER.error(format(
                        "Found a foreign key in table '%s' with no name. " +
                        "Assigning it a random name '%s'",
                        table.getId(), randName));
                }
            });

    }
'true' below might speed up metadata retrieval since approximations can
be used. See https://github.com/speedment/speedment-enterprise/issues/168
runtime-parent/runtime-connector-parent/sqlite/src/main/java/com/speedment/runtime/connector/sqlite/internal/SqliteMetadataHandlerImpl.java