我尝试将多个应用程序分组到“app”文件夹中,以便更好地进行管理。但是当我第一次迁移时,我得到了以下错误。
./manage.py makemigrations
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 132, in handle
migration_name=self.migration_name,
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 45, in changes
changes = self._detect_changes(convert_apps, graph)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 128, in _detect_changes
self.old_apps = self.from_state.concrete_apps
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/migrations/state.py", line 166, in concrete_apps
self.apps = StateApps(self.real_apps, self.models, ignore_swappable=True)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/migrations/state.py", line 228, in __init__
self.render_multiple(list(models.values()) + self.real_models)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/migrations/state.py", line 296, in render_multiple
model.render(self)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/migrations/state.py", line 585, in render
body,
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/models/base.py", line 158, in __new__
new_class.add_to_class(obj_name, obj)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/models/base.py", line 299, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/models/fields/related.py", line 702, in contribute_to_class
super(ForeignObject, self).contribute_to_class(cls, name, virtual_only=virtual_only)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/models/fields/related.py", line 308, in contribute_to_class
lazy_related_operation(resolve_related_class, cls, self.remote_field.model, field=self)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/models/fields/related.py", line 85, in lazy_related_operation
return apps.lazy_model_operation(partial(function, **kwargs), *model_keys)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/models/fields/related.py", line 83, in <genexpr>
model_keys = (make_model_tuple(m) for m in models)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/models/utils.py", line 14, in make_model_tuple
app_label, model_name = model.split(".")
ValueError: too many values to unpack
我为分割的模型添加了一个print语句,输出为:
auth.User
auth.Group_permissions
auth.User_groups
auth.User_user_permissions
app.ticketmgr.BasePriority
似乎“app.ticketmgr.BasePriority”有一个额外的“点”。实际上,应用程序名称是“ticketmgr”,但放在“app”文件夹中以便更好地管理。我可以知道如何使迁移工作吗?是否有任何额外的设置来支持将几个应用程序放在“app”文件夹中? 下面是我的app文件夹,里面有2个应用程序(comm,ticketmgr)。
|____app
| |______init__.py
| |____comm
| | |______init__.py
| | |____admin.py
| | |____apps.py
| | |____migrations
| | | |______init__.py
| | |____models.py
| | |____role_required.py
| | |____tests.py
| | |____views.py
| |____ticketmgr
| | |______init__.py
| | |____admin.py
| | |____apps.py
| | |____forms.py
| | |____migrations
| | | |____0001_initial.py
| | | |______init__.py
| | |____models.py
| | |____tests.py
| | |____views.py
答案 0 :(得分:1)
不需要更多。只需将"app.ticketmgr", "app.comm"
添加到INSTALLED_APPS
。
答案 1 :(得分:0)
BasePriority未出现在您的项目目录中。也许它是一个模特?
已安装的应用行应为:
app.ticketmgr
由于BasePriority不存在,django获得3个参数,而不是app_label,model_name所需的2个参数。 &#34; BasePriority&#34;是第三个参数,除了。