当我尝试管理.py makemigration时,出现了一个错误:
我的模型是:
class Burger(models.Model):
title = models.CharField(max_length=100)
mt = models.CharField(max_length=50)
description = models.TextField(max_length=255)
price = models.IntegerField()
img = models.ImageField()
class Comment(models.Model):
author = models.CharField(max_length=50)
email = models.CharField(max_length=100)
text = models.TextField(max_length=255)
date = models.DateTimeField()
bid = models.ForeignKey('Burger', on_delete=models.CASCADE)
回溯是:
Traceback (most recent call last):
File "C:\Burger123\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 327, in execute
django.setup()
File "C:\Python27\lib\site-packages\django\__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\Python27\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Burger123\BURRGER\models.py", line 15, in <module>
class Comment(models.Model):
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 158, in __new__
new_class.add_to_class(obj_name, obj)
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 299, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 703, in contribute_to_class
super(ForeignObject, self).contribute_to_class(cls, name, virtual_only=virtual_only)
File "C:\Python27\lib\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 "C:\Python27\lib\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 "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 83, in <genexpr>
model_keys = (make_model_tuple(m) for m in models)
File "C:\Python27\lib\site-packages\django\db\models\utils.py", line 13, in make_model_tuple
app_label, model_name = model.split(".")
ValueError: too many values to unpack
我的设置是:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'BURRGER.apps.BurrgerConfig'
]
INSTALLED_APPS
:from django.apps import AppConfig
class BurrgerConfig(AppConfig):
name = 'BURRGER'
label = 'my.burger'
我删除了
BurrgerConfig
行,并使迁移无误地结束。但我的代码中完全需要这一行,所以问题仍然悬而未决。 最佳答案
应用程序配置中的label
不应包含点。你可以这样做:
class BurrgerConfig(AppConfig):
name = 'BURRGER'
label = 'burger'
你的代码更混乱,因为你在你的代码和目录名中错放了'BURRGER'。Python/Django中通常的方法是
burger - directory name, name and lable in app config class
Burger - model name
BurgerConfig - App Config class name
关于mysql - Makemigrations ValueError:太多值无法解包,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35155095/