33
votes

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.

7

7 Answers

31
votes
dev_appserver.py --clear_datastore=yes myapp

See here for more info.

Shorthand version:

dev_appserver.py -c
20
votes

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.

4
votes

dev_appserver.py [app directory] --clear_datastore true

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

2
votes

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)

0
votes

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

0
votes

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.

-1
votes

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('.')