i have written data migration file creating initial data mptt model.
but creation fails,
def create_foo(apps, schema_editor): db_alias = schema_editor.connection.alias logger = logging.getlogger(__name__) foo = apps.get_model("app", "foo") attr in roles: try: foo = foo.objects.using(db_alias).get(name=attr[0]) except foo.doesnotexist: parent = foo.objects.using(db_alias).get(name=attr[1]) if attr[1] else none if parent: foo = foo.objects.create(name=attr[0], parent=parent) else: foo = foo.objects.using(db_alias).create(name=attr[0]) logger.info("created foo - %s" % foo) i getting below error while executing below line, ideas?
foo = foo.objects.using(db_alias).create(name=attr[0])
file "/library/frameworks/python.framework/versions/2.7/lib/python2.7/site-packages/mysqldb/connections.py", line 36, in defaulterrorhandler raise errorclass, errorvalue django.db.utils.integrityerror: (1048, "column 'lft' cannot null")
you have manually register model mptt:
from mptt import register def create_foo(apps, schema_editor): db_alias = schema_editor.connection.alias logger = logging.getlogger(__name__) foo = apps.get_model("app", "foo") register(foo) # ... rest of code...
Comments
Post a Comment