Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composite Key (clustering columns) is throwing error #114

Open
CaliBitcoins opened this issue Mar 31, 2018 · 2 comments
Open

Composite Key (clustering columns) is throwing error #114

CaliBitcoins opened this issue Mar 31, 2018 · 2 comments

Comments

@CaliBitcoins
Copy link

Hello, trying to get a Django/Cassandra project off the ground, but when I attempt to create some cql tables with composite keys in models.py I receive an error that instructs me to write an additional class. Has anyone else encountered this issue?

in models.py:
`from django.db import models
from cassandra.cqlengine import columns
from django_cassandra_engine.models import DjangoCassandraModel

class Article(DjangoCassandraModel):
slug = columns.Text(primary_key=True)
published = columns.DateTime(primary_key=True, clustering_order="DESC")
title = columns.Text(required=True)
author = columns.Text(required=True)
body = columns.Text(required=True)
thumb = columns.Bytes(required=False)`

when I python manage.py runserver OR sync_cassandra I get the following error:

`Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/django_cassandra_engine/models/init.py", line 848, in _get_explicit_pk_column
pk_field = cls.Meta.get_pk_field
AttributeError: type object 'Article' has no attribute 'Meta'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "manage.py", line 15, in
execute_from_command_line(sys.argv)
File "/home/shine/.local/lib/python3.5/site-packages/django/core/management/init.py", line 371, in execute_from_command_line
utility.execute()
File "/home/shine/.local/lib/python3.5/site-packages/django/core/management/init.py", line 347, in execute
django.setup()
File "/home/shine/.local/lib/python3.5/site-packages/django/init.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/shine/.local/lib/python3.5/site-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/home/shine/.local/lib/python3.5/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.5/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 673, in _load_unlocked
File "", line 665, in exec_module
File "", line 222, in _call_with_frames_removed
File "/home/shine/cs/coinsector/articles/models.py", line 9, in
class Article(DjangoCassandraModel):
File "/usr/local/lib/python3.5/dist-packages/django_cassandra_engine/models/init.py", line 448, in new
name=name
File "/usr/local/lib/python3.5/dist-packages/django_cassandra_engine/models/init.py", line 505, in _add_django_meta_and_register_model
'_meta', DjangoCassandraOptions(meta, app_label, cls=new_class))
File "/usr/local/lib/python3.5/dist-packages/django_cassandra_engine/models/init.py", line 60, in init
self.setup_pk()
File "/usr/local/lib/python3.5/dist-packages/django_cassandra_engine/models/init.py", line 78, in setup_pk
self.pk = self.model_inst._get_explicit_pk_column()
File "/usr/local/lib/python3.5/dist-packages/django_cassandra_engine/models/init.py", line 850, in _get_explicit_pk_column
raise RuntimeError(PK_META_MISSING_HELP.format(cls))
RuntimeError:
On Django Cassandra Models with more than one primary_key field,
The model <class 'articles.models.Article'> must specify class Meta attribute 'get_pk_field'.
E.g.
class Meta:
get_pk_field='id'
So that Django knows which primary key field to use in queryies such as Model.objects.get(pk=123)
`
Any assistance would be very much appreciated! Thanks!

@bicepjai
Copy link

Did you get a solution for this ?

@caniko
Copy link

caniko commented Oct 24, 2021

This is also a little counterintuitive, considering that Cassandra should accept multiple primary keys. This be solved intrinsically, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants