django-compositekey包出错

时间:2015-09-25 10:34:06

标签: python django composite-key

我的django项目中需要一个复合键。我找到this projects并尝试使用它。

class Loccupy(models.Model):

    id = db.MultiFieldPK('lolockcode', 'loroomcode', 'loindate', 'loopercd')

    lolockcode = models.IntegerField(blank=True, null=True,
    loroomcode = models.IntegerField(blank=True, null=True,)
    loindate = models.DateField(blank=True, null=True,)
    loopercd = models.IntegerField(blank=True, null=True,)

但是我犯了一个错误:

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/.../lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/.../lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/home/.../lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/.../lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/.../lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/home/.../.pyenv/versions/2.7.10/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/.../models.py", line 133, in <module>
class Loccupy(models.Model):
File "/home/.../lib/python2.7/site-packages/django/db/models/base.py", line 282, in __new__
new_class._prepare()
File "/home/.../lib/python2.7/site-packages/django/db/models/base.py", line 306, in _prepare
opts._prepare(cls)
File "/home/.../lib/python2.7/site-packages/compositekey/db/models/fields/wrap.py", line 13, in _prepare
for prepare_action in getattr(opts, "_lazy_prepare_field_actions", []): prepare_action()
File "/home/.../lib/python2.7/site-packages/compositekey/db/models/fields/multiplekey.py", line 71, in lazy_init
cls._meta.unique_together.append(names)
AttributeError: 'tuple' object has no attribute 'append'

这个错误是什么原因?我在自述文件中编写了我的代码。 也许,它是另一个添加复合键的包? 我需要一个复合键,而不是unique_together。我有一个现有的数据库?只有这四列,并且这一列中没有一个不独特。只有全部四列可能是唯一的。

0 个答案:

没有答案