How do I delete all entities from my local Google App-engine datastore?

懵懂的女人 提交于 2019-11-29 06:05:58

问题


How can I remove all entities or reset the local datastore on my dev_appserver? I accidentally recursively called a function to create an entity when testing.

I am using the Google App-engine SDK on Vista with Python.


回答1:


dev_appserver.py --clear_datastore=yes myapp

See here for more info.

Shorthand version:

dev_appserver.py -c



回答2:


If you came here for a Java solution: Delete the following file:

{project root}/WEB-INF/appengine-generated/local_db.bin

Rebuild and restart your project.




回答3:


dev_appserver.py [app directory] --clear_datastore true

you need to shutdown the server if its running at the time to free the ports




回答4:


A useful thing to do is to always specify --datastore_path, e.g. --datastore_path=test.datastore.

To delete it you can then just delete the file. You can also keep copies and swap them in and out. And the store will persist over reboots (when /tmp/ the default location for it on Linux anyway, gets cleared)




回答5:


In production - you can go to appengine dashboard => Datastore admin




回答6:


Here is my output after running dev_appserver

INFO     2017-03-21 15:07:36,085 devappserver2.py:764] Skipping SDK update check.
INFO     2017-03-21 15:07:38,342 api_server.py:268] Starting API server at: http://localhost:63970
INFO     2017-03-21 15:07:38,349 dispatcher.py:199] Starting module "default" running at: http://localhost:8080
INFO     2017-03-21 15:07:38,373 admin_server.py:116] Starting admin server at:

So I go to http://localhost:8000 and I am able to go to my local App Engine Admin Console and edit/delete datastore entities.




回答7:


in production, this may also come in handy (or be a security nightmare).

# will DELETE the database use http://localhost:8083/deletemodels?force=true
class DeleteModels(webapp.RequestHandler):
    def get(self):

    def dMsg(msg):
      self.response.out.write(msg + '\n')
    n = self.request.get('force')
    if n:
      dMsg('clearing YourModelHere data....')
      for uc in YourModelHere.all():
               uc.delete()
               dMsg('.')
      dMsg('clearing YouNextModelHere data....')           
      for uc in YouNextModelHere.all():
               uc.delete()
               dMsg('.')     


来源:https://stackoverflow.com/questions/1010573/how-do-i-delete-all-entities-from-my-local-google-app-engine-datastore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!