create collection with python code

故事扮演 提交于 2019-12-07 17:59:31

The problem is that you're running the code directly within the definition of GalleryPage:

class GalleryPage(Page):
    # test
    root_coll = Collection.get_first_root_node()
    root_coll.add_child(name='testcoll')

This will run every time models.py is loaded - and in particular, the ./manage.py makemigrations and ./manage.py migrate commands need to load models.py in order to find out how to set your database up. Creating database objects is naturally going to fail at that point, because the database isn't ready yet...

The best place to run test code like this is probably the ./manage.py shell command line, where you should be able to run the following lines successfully:

from wagtail.wagtailcore.models import Collection
root_coll = Collection.get_first_root_node()
root_coll.add_child(name='testcoll')
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!