jelly
jelly

Reputation: 11

Instance of 'MongoEngine' has no 'StringField' member

Trying to create a models for WTForms using Mongo Engine according to the documentation here and getting the error returned Instance of 'MongoEngine' has no 'StringField' member when trying to create a model as such

class Example(db.Document):
      Value = db.StringField(max_length=200)

Upvotes: 1

Views: 1065

Answers (1)

BZ_M97
BZ_M97

Reputation: 186

The workaround is to use mongoengine package directly, which is installed as a dependency of flask_mongoengine.

from mongoengine import StringField

class Example(db.Document):
  value = StringField(max_length=200)

The error is provided by pylint - a code analysis tool for python, it just fails to validate dynamic members of db. Your code is correct it will won't fail at runtime.

Another option is to setup project .pylintrc to silence such warnings, or place pylint comments over the line displaying error:

# pylint: disable=no-member
value = db.StringField(max_length=200) # no error

Upvotes: 2

Related Questions