syncdb fails with django-compositekey
Question: I'm planning to use django-compositekey to connect to a legacy db that makes
use of compound keys. Just to see that everything is working, I created a new
Django project with a simple model like this.

    
    
    from django.db import models
    from compositekey import db
    
    class Book(models.Model):
    id = db.MultiFieldPK("author", "name")
    name = models.CharField(max_length=100)
    author = models.CharField(max_length=100)
    

if I use django_manage.py sql Books everything seems to be fine, I receive

    
    
     BEGIN;
    CREATE TABLE "Books_book" (
    "name" varchar(100) NOT NULL,
    "author" varchar(100) NOT NULL,
    UNIQUE ("author", "name"),
    PRIMARY KEY ("author", "name")
    )
    ; 
    
    COMMIT;
    

However, when I try to use syncdb I receive the following error

    
    
    Creating tables ...
    Traceback (most recent call last):
    File "/home/islas/pycharm-3.4.1/helpers/pycharm/django_manage.py", line 23, in <module>
    run_module(manage_file, None, '__main__', True)
    File "/usr/lib/python2.7/runpy.py", line 176, in run_module
    fname, loader, pkg_name)
    File "/usr/lib/python2.7/runpy.py", line 82, in _run_module_code
    mod_name, mod_fname, mod_loader, pkg_name)
    File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
    File "/home/islas/PycharmProjects/BooksDemo/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line           399, in execute_from_command_line
    utility.execute()
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line   392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 415,  in handle
    return self.handle_noargs(**options)
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 112, in handle_noargs
    emit_post_sync_signal(created_models, verbosity, interactive, db)
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/sql.py", line 216, in emit_post_sync_signal
    interactive=interactive, db=db)
    File "/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.py", line 185, in send
    response = receiver(signal=self, sender=sender, **named)
    File "/usr/local/lib/python2.7/dist-   packages/django/contrib/auth/management/__init__.py", line 93, in create_permissions
    "content_type", "codename"
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 538, in values_list
    _fields=fields)
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 852, in _clone
    c._setup_query()
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 995, in _setup_query
    self.query.add_fields(self.field_names, True)
    File "/usr/local/lib/python2.7/dist-packages/compositekey/db/models/sql/query.py", line 24, in add_fields
    True)
    ValueError: need more than 5 values to unpack
    
    Process finished with exit code 1
    

Does anybody have an idea of what might be wrong? I'm new to Django, but as
far as I read working with compound primary keys is now possible using django-
compositekey.

Thanks in advance,

Alejandro


Answer: Which version of `Django` you are using...? I got the same problem because i
was using `Djnago 1.5.8` and the `compositekey` package does not support
Djnago 1.5.8

For composite primary keys, you can use
[SQLAlchemy](http://www.sqlalchemy.org/) instead of native Django ORM. It can
coexist with Django ORM seamlessly.

