TAGS :Viewed: 5 - Published at: a few seconds ago

[ Primary key in google app engine ]

I am creating one to many relationship using the following data model. How can I make primary key and foreign key?

class Candidate(db.Model):
    name = db.StringProperty()
    lastname = db.StringProperty()
    email = db.StringProperty()
    mobno = db.StringProperty()
    grad = db.StringProperty()
    pg = db.StringProperty()
    cloc = db.StringProperty()
    ploc = db.StringProperty()

class Skills(db.Model)
    skillcode=db.IntegerProperty()
    skillname=StringProperty()

Each candidate have many skills. How can I make primary key and foreign key?

Answer 1


The app engine datastore does not work like relational databases such as mysql or sqlite. It's a schemaless database. Every model has a key. This key can be defined by an id and/or a key name. You can pass a key_name as a keyword argument when you instantiate a model, whereas in most cases, id's are automatically assigned.

A ReferenceProperty could be seen as the equivalent of a foreign key. This property can hold another model instance" as a value, and using keyword arguments, you can specify a kind that the model has to be.

The python runtime on appengine has two datastore modules, one called db, and one called ndb. Take a look at ndb, it's the newer api, and helps you with caching; I also find it has an easier to use api.