Changing StringProperty to TextProperty of existing AppEngine DataStore entity without losing data

199 views
Skip to first unread message

Heisenberg W

unread,
May 16, 2019, 12:29:38 PM5/16/19
to Google App Engine

I have a django project and I want to change property type of one of the models. My current model.py is:

class Person(ndb.Model):
    property_one= ndb.StringProperty()
    property_two= ndb.StringProperty()

and I want to change it to:

class Person(ndb.Model):
    property_one= ndb.TextProperty()
    property_two= ndb.TextProperty()

Both of my properties already have data and I cannot store more than 1500 bytes. So I want to convert from string to text without losing any data. How can I achieve this?

Harmit Rishi (Cloud Platform Support)

unread,
May 17, 2019, 10:16:46 PM5/17/19
to Google App Engine
Hi, 

The following documentation here provides an example for db.TextProperty() which may be of some use for you. However before moving forward, would you be able to clarify your use case of converting StringProperty() to TextProperty()? 

I ask this because indeed TextProperty value can be more than 1500 bytes long. However, these values are not indexed and cannot be used in filters or sort orders. Additionally, TextProperty values store text with text encoding. Due to this, I am trying to determine if you require binary data. If so, you may consider BlobProperty

Vitaly Bogomolov

unread,
May 18, 2019, 12:30:30 PM5/18/19
to Google App Engine

Heisenberg W

unread,
May 20, 2019, 3:37:45 PM5/20/19
to Google App Engine
Thanks for the response.

I have already seen that expando answer in stackoverflow and I was having trouble with one thing.
From stackoverflow:

Before:

class Person(db.Model):
    name = db.StringProperty()
    age = db.StringProperty() #this will go to int

After

class Person(db.Expando):
    pass

for person in Person.all():
    person.age = int(person.age)
    person.put()

Very after:

class Person(db.Model):
    name = db.StringProperty()
    age = db.IntegerProperty() 
Do I have to write all this in models.py file? Including the for loop? I put the similar code in models.py file and nothing happened. I want to use expando but it doesn't work.

Heisenberg W

unread,
May 20, 2019, 3:37:53 PM5/20/19
to Google App Engine
The project is storing references to photo links stored in filestack. I want neither indexing nor encoding.

Tiago (Google Cloud Platform Support)

unread,
May 27, 2019, 7:10:54 PM5/27/19
to Google App Engine
Google Groups hosts discussion forums where you can find information like service status updates, release notes and high-level discussions on the state of the platform. For coding and programming assistance, you're better served in dedicated forums such as Stack Overflow, where experienced programmers are within reach and ready to help. 

Thank you for understanding.

Reply all
Reply to author
Forward
0 new messages