def METHOD_NAME(self, *args, **options):
    # Get the list of databases to create
    databaselist = options["database"]
    if databaselist:
        if databaselist in settings.DATABASES:
            databaselist = [databaselist]
        else:
            raise CommandError("No database settings known for '%s'" % databaselist)
    else:
        databaselist = settings.DATABASES.keys()
    for database in databaselist:
        # Connect to the database
        import psycopg2
        user = options["user"] or settings.DATABASES[database].get("USER", "")
        password = options["password"] or settings.DATABASES[database].get(
            "PASSWORD", ""
        )
        conn_params = {"database": "template1"}
        if user:
            conn_params["user"] = user
        if password:
            conn_params["password"] = password
        database_host = settings.DATABASES[database].get("HOST", None)
        if database_host:
            conn_params["host"] = database_host
        database_port = settings.DATABASES[database].get("PORT", None)
        if database_port:
            conn_params["port"] = database_port
        database_name = settings.DATABASES[database].get("NAME", None)
        if not database_name:
            raise CommandError("No database name specified")
        connection = psycopg2.connect(**conn_params)
        connection.set_isolation_level(0)  # enforce autocommit
        with connection.cursor() as cursor:
            # Check if the database exists
            cursor.execute(
                "SELECT count(*) AS result FROM pg_database where datname = '%s'"
                % database_name
            )
            database_exists = cursor.fetchone()[0]
            if database_exists:
                if options["skip_if_exists"]:
                    print("Database %s already exists" % database_name.upper())
                    continue
                # Confirm the destruction of the database
                if options["interactive"]:
                    confirm = input(
                        "\nThe database %s is about to be IRREVERSIBLY destroyed and recreated.\n"
                        "ALL data currently in the database will be lost.\n"
                        "Are you sure you want to do this?\n"
                        "\n"
                        "Type 'yes' to continue, or 'no' to cancel: "
                        % database_name.upper()
                    )
                    if confirm != "yes":
                        print(
                            "Skipping drop and create of database %s"
                            % database_name.upper()
                        )
                        continue
                # Close current connections
                try:
                    cursor.execute(
                        """
                            SELECT pg_terminate_backend(pg_stat_activity.pid)
                            FROM pg_stat_activity
                            WHERE pg_stat_activity.datname = '%s'
                            """
                        % database_name
                    )
                except psycopg2.ProgrammingError as e:
                    raise CommandError(str(e))
                # Drop the database
                try:
                    sql = 'drop database "%s"' % database_name
                    print("Executing SQL statement:", sql)
                    cursor.execute(sql)
                except psycopg2.ProgrammingError as e:
                    raise CommandError(str(e))
            # Create the database
            try:
                sql = "create database \"%s\" encoding = 'UTF8'" % database_name
                if settings.DEFAULT_TABLESPACE:
                    sql += " TABLESPACE = %s" % settings.DEFAULT_TABLESPACE
                print("Executing SQL statement:", sql)
                cursor.execute(sql)
            except psycopg2.ProgrammingError as e:
                raise CommandError(str(e))