tamboril
tamboril

Reputation: 3

How do I delete the Kind entity, itself in Google App Engine?

I know all my data are cleared out by default every time I restart the development server on Google App Engine, but I need to know that when I start deploying, I can programmatically delete not just the entities of all the Kinds, but also the Kind entities, themselves, as I change them during development/deployment cycles.

Looking at similar questions, I came up with this attempt:

from model import *
from google.appengine.ext.db import *
from google.appengine.ext.db.metadata import *

for i in Kind.all():
    if i.kind_name == 'Person':
        i.delete() # Try one way
        db.delete(i) # Try another way
        print "Yes"
        break

...but this prints "Yes" every time, indicating that the 'Person' kind is not being deleted. Is this just an artifact of the development server, or can you never delete Kind entities?

Upvotes: 0

Views: 767

Answers (1)

Guido van Rossum
Guido van Rossum

Reputation: 16890

You cannot delete the Kind returned by a metadata query. The App Engine Datastore has a dynamic schema that will automatically adapt when you delete the last entity of a kind. It is possible that the dev appserver has some lag here -- or possibly you are mistaken that the Datastore is deleted each time, since this not supposed to happen. What makes you think that it does?

PS. Don't use import * so much, it makes your code harder to read and might cause bugs due to name conflicts...

Upvotes: 3

Related Questions