I have a base document class Feed
from which RSS
and Channels
inherit. Here is the definition:
class Feed(Document):
meta_info = EmbeddedDocument(MetaInfo, default=MetaInfo, required=True)
name = StringField()
link = StringField()
meta = {'allow_inheritance': True}
I want my two other classes, RSS
and Channels
, to be able to inherit the Feed
document with its embedded document MetaInfo
. However, when the whole file is run, alongside the following code:
class Channel(Feed):
channel_id = IntField(primary_key=True, unique=True, required=True)
update_interval = IntField(default=300, required=True)
# similar class for RSS but with different fields
I get the following error:
File "/Users/komron/dev/github/courant/src/models/channels.py", line 9, in <module>
class Channel(Feed):
File "/Users/komron/.local/share/virtualenvs/courant-Dv7-v42z/lib/python3.7/sitepackages/mongoengine/base/metaclasses.py", line 407, in __new__
raise ValueError("Cannot override primary key field")
ValueError: Cannot override primary key field
What am I doing wrong? Are there any restrictions placed on inheritance with MongoEngine that I should be aware of? Thanks.