How to delete all datastore in Google App Engine?

后端 未结 29 1924
夕颜
夕颜 2020-11-28 01:17

Does anyone know how to delete all datastore in Google App Engine?

29条回答
  •  天命终不由人
    2020-11-28 01:49

    Here's how I did this naively from a vanilla Google Cloud Shell (no GAE) with python3:

    from google.cloud import datastore
    client = datastore.Client()
    query.keys_only()
    for counter, entity in enumerate(query.fetch()):
        if entity.kind.startswith('_'):  # skip reserved kinds
            continue
        print(f"{counter}: {entity.key}")
        client.delete(entity.key)
    

    This takes a very long time even with a relatively small amount of keys but it works.

    More info about the Python client library: https://googleapis.dev/python/datastore/latest/client.html

提交回复
热议问题