Knotis / djangocassandra

Cassandra support for the Django web framework
BSD 3-Clause "New" or "Revised" License
12 stars 4 forks source link

KeyError When migrating #48

Open Ace314159 opened 9 years ago

Ace314159 commented 9 years ago

I installed djangocassandra and djangotoolbox, but when I run python manage.py migrate. I get KeyError: 'DEFAULT_KEYSPACE'

simlay commented 9 years ago

What's your django settings.py say? It should be something like:

DATABASES = {
    'default': {
        'ENGINE': 'djangocassandra.db.backends.cassandra',
        'NAME': 'DATABASE NAME',
        'USER': '',
        'PASSWORD': '',
        'HOST': 'YOUR DATABASE HOST',
        'CONTACT_POINTS': ('YOUR DATABASE HOST',),
        'PORT': 9042,
        'DEFAULT_KEYSPACE': 'YOUR KEYSPACE NAME',
        'KEYSPACES': {
            'YOUR KEYSPACE NAME':{
                'durable_writes': True,
                'strategy_class': 'SimpleStrategy',
                'replication_factor': 3
            }
        }
    }
}

The documentation is a little lacking.

Ace314159 commented 9 years ago

Thanks for the especially quick reply. I changed the settings.py and it worked properly. Also, I am trying to use the included AutoFieldUUID, but the documentation does not clearly explain what to import. I tried to import djangocassandra, but I get the error message OSEror: zipimport: can not open file PythonDir/lib/site-packages/django-cassandra-0.1.7-py3.4.egg

EDIT: Sorry. I fixed it. I was running the import from interactive mode. It works in code. Thanks for this amazing engine!

simlay commented 9 years ago

Sure!

That setting is: CUSTOM_AUTOFIELD_CLASS = 'djangocassandra.db.fields.AutoFieldUUID'

For debug purposes, you may try not using the CUSTOM_AUTOFIELD_CLASS and this will make all the pk fields to be integers (I think).

What version of python are you using?

Ace314159 commented 9 years ago

Oops, didn't see your comment. I use Python 3.4. I tried CUSTOM_AUTOFIELD_CLASS, but that didn't work out, so I'm going to stick with importing djangocassandra.db.fields.

simlay commented 9 years ago

Cool. Good luck.

Ace314159 commented 9 years ago

I have another problem now. I installed the Knotis Fork of Django, added the CUSTOM_AUTOFIELD_CLASS setting, but now I get this: cassandra.cqlengine.models.ModelDefinitionException: At least 1 primary key is required. I already defined a AutoField(primary_key=True) field.

simlay commented 9 years ago

Hmm... What's your model look like?

The project isn't tested with Python 3.4. If you run the test suite (nose test I believe) do you get a similar result?

Ace314159 commented 9 years ago

I didn't setup any tests yet so I don't know how to run nose test. My models.py is:

#search/models.py
from django.db import models
import uuid

class Person(models.Model):
    pID = models.AutoField(primary_key=True, default=uuid.uuid4, unique=True)
    pFname = models.CharField(max_length=100)
    pMname = models.CharField(max_length=100)
    pSname = models.CharField(max_length=100)
    pAge = models.IntegerField(max_length=3)
    pSex = models.CharField(max_length=1)
    pEd = models.CharField(max_length=100)
    pIncome = models.DecimalField(max_length=100, decimal_places=10, max_digits=100)
    pNet = models.DecimalField(max_length=100, decimal_places=10, max_digits=100)
    pStreetNum = models.IntegerField(max_length=100)
    pStreet = models.CharField(max_length=100)
    pSuburb = models.CharField(max_length=100)
    pCity = models.CharField(max_length=100)
    pDistrict = models.CharField(max_length=100)
    pState = models.CharField(max_length=2)
    pPin = models.BigIntegerField()
    pLat = models.DecimalField(max_length=1000, decimal_places=20, max_digits=1000)
    pLong = models.DecimalField(max_length=1000, decimal_places=20, max_digits=1000)

    if(pSex == "F"):
        gender = "female"
        pronoun = "She"
    else:
        gender = "male"
        pronoun = "He"

    def __str__(self):
        return "{0} {1} {2} is a {3} who is {4} years old. {5} has completed {6}, earns {7}, and has a networth of {8}. {5} \
        lives in  {9}, {10}, {11}, {12}, {13}, {14}, {15} ({16} degress North, {17} degrees East). ID: {18}".format(self.pFname, self.pMname, \
        self.pSname, self.gender, self.pAge, self.pronoun, self.pEd, self.pIncome, self.pNet, self.pStreetNum, self.pStreet, self.pSuburb, self.pCity, self.pDistrict, self.pPin, self.pState, self.pLat, self.pLong, self.pID)

EDIT: Also, the error occurs even when my app is not installed.

sethdenner commented 8 years ago

It's possible that the dependencies in the setup.py are not as specific as they need to be and something has been updated or changed underneath this project.

I'm making some improvements to the library today and I'll ship a new working version.

sethdenner commented 8 years ago

Oh I read all the comments now and I'm not sure this library supports python3 as I have not tested it. I have a feeling that you are running into compatibility issues somewhere either in this library or the supporting ones.

Here's the documentation about how to configure the AutoUUID field: https://djangocassandra.readthedocs.org/en/latest/usage.html#usage

sethdenner commented 8 years ago

oh and the import for the example is:

from djangocassandra.db.fields import AutoFieldUUID