Joshua Fox
Joshua Fox

Reputation: 19675

In Google Datastore, how do I transfer an entity, which references another entity, from one project to another?

An entity key (e.g. urlsafe key) includes the project identifier. I.e, these keys are built something like projectID+kind+entityId. These keys can be stored in a field of one entity as a reference to another entity.

So, when you copy part or all of a database between Google Cloud projects -- for example, as a backup or to create a testing environment -- all references between entities are broken.

How can we safely copy entities between projects?

Upvotes: 1

Views: 471

Answers (1)

minou
minou

Reputation: 16563

If your entity has a key (assuming Python) like this:

    some_key = ndb.KeyProperty()

then this key will not break when you transfer to a new project. This key does not include the project ID.

If you store urlsafe keys in your entities, then you will need to update them all when you transfer data to a new project because a urlsafe key does include the project ID.

You probably shouldn't be storing urlsafe keys unless you have multiple projects interacting with one another.

Upvotes: 3

Related Questions