Django,我收到“错误:模块:模型无法导入”而manage.py check或sync.db

时间:2015-11-27 16:27:45

标签: python django eclipse

将我的应用程序添加到INSTALLED_APPS部分之后,我无法制作 python manage.py check - 它返回错误。 请你帮我找出我做错了什么?

1)console window with an error @line55 of models.py

控制台文字:

  

(py350-dja185-venv)MacBook-Pro:recipe_1_1 mac1 $ python manage.py check   shell Traceback(最近一次调用最后一次):文件“manage.py”,第10行,   在       execute_from_command_line(sys.argv)文件“/Users/mac1/Envs/py350-dja185-venv/lib/python3.5/site-packages/django/core/management/init.py”,行351,在execute_from_command_line中       utility.execute()文件“/Users/mac1/Envs/py350-dja185-venv/lib/python3.5/site-packages/django/core/management/init.py”,第325行,执行中       django.setup()文件“/Users/mac1/Envs/py350-dja185-venv/lib/python3.5/site-packages/django/init.py”,   第18行,在设置中       apps.populate(settings.INSTALLED_APPS)文件“/Users/mac1/Envs/py350-dja185-venv/lib/python3.5/site-packages/django/apps/registry.py”,   第108行,填充       app_config.import_models(all_models)文件“/Users/mac1/Envs/py350-dja185-venv/lib/python3.5/site-packages/django/apps/config.py”,   第198行,在import_models中       self.models_module = import_module(models_module_name)文件“/Users/mac1/Envs/py350-dja185-venv/lib/python3.5/importlib/init.py”,   第126行,在import_module中       return _bootstrap._gcd_import(name [level:],package,level)文件“”,第986行,在_gcd_import文件中   “”,第969行,在_find_and_load文件中   “”,第958行,在_find_and_load_unlocked中   文件“”,第673行,在_load_unlocked中   文件“”,第662行,in   exec_module文件“”,第222行,in   _call_with_frames_removed文件“/Users/mac1/Documents/workspace/recipe_1_1/meals/models.py”,第55行,   在       class Ingredients(models.Model):文件“/Users/mac1/Envs/py350-dja185-venv/lib/python3.5/site-packages/django/db/models/base.py”,   第308行, new       new_class._prepare()文件“/Users/mac1/Envs/py350-dja185-venv/lib/python3.5/site-packages/django/db/models/base.py”,   第361行,在_prepare中       cls。 doc =“%s(%s)”%(cls。 name ,“,”。join(f.name for opts.fields中的f))TypeError :序列项7:预期的str实例,int   结果

2)一段代码@ models.py为什么它在第55行给我一个错误?

36-39 MEASUREMENT_CHOICES = (('шт', 'штук'), ...,)

41 class Recipe(models.Model):
42     recipe_id = models.PositiveIntegerField()
43     meal_id = models.ForeignKey('Meal')
44     ingredient_id = models.ForeignKey('Ingredients', related_name = '+')
45     ingr_quantity = models.PositiveSmallIntegerField()
46     ingr_measurement = models.CharField(max_length = 5, choices = MEASUREMENT_CHOICES)
47     tail = models.CharField(max_length = 35) 

49 SEASON_CHOICES = ((u'01', u'январь'), (u'02', u'февраль'), (u'03', u'март'),
                  (u'04', u'апрель'), (u'05', u'май'), (u'06', u'июнь'),
                  (u'07', u'июль'), (u'08', u'август'), (u'09', u'сентябрь'),
                  (u'10', u'октябрь'), (u'11', u'ноябрь'), (u'12', u'декабрь'),  
                  )

55 class Ingredients(models.Model):
56    ingr_name = models.CharField(max_length = 20)
57    ingr_category = models.ForeignKey('IngrCategory') 
58    calories_raw = models.PositiveSmallIntegerField()
59    calories_boiled = models.PositiveSmallIntegerField()
60    calories_fried = models.PositiveSmallIntegerField()
61    ingr_unit = models.CharField(10)
62    price_in_season = models.DecimalField(7,2)
63    price_in_no_season = models.DecimalField(7,2)
64    price_current = models.DecimalField(7,2)
65    season = models.CharField(max_length = 2, choices = SEASON_CHOICES)

不知何故,它通过了Recipe类,也通过上一个类,并在class Ingredients(models.Model)行给出了一个错误。为什么呢?

3)eclipse窗口 - 同一个项目,不同的错误类型:

  

查找文件...已完成。   导入测试模块......完成。   追踪(最近一次呼叫最后):< ...>   在run_tests中输入文件“/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev_4.3.0.201508182223/pysrc/pydev_runfiles.py”,第813行       引发AssertionError(“无法使用DjangoTestSuiteRunner运行套件,因为它无法导入。”)   AssertionError:无法使用DjangoTestSuiteRunner运行套件,因为它无法导入。

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:1)

问题在于缺少" max_digits ="和" decimal_places ="

62    price_in_season = models.DecimalField(max_digits = 7, decimal_places = 2)

此字段是Ingredients类中序列的第7个。