Python 如何将Django连接到Cassandra数据库?
我有一个项目,我必须使用卡桑德拉数据库与Django一起开发。我查看了这些文档,但只有关于mysql、sklite和postgre数据库的信息,没有关于Cassandra的信息。我正在寻找连接Django和Cassandra的示例方法: 我知道我必须在setting.py文件中设置数据库配置: 但它抛出了一个错误:Python 如何将Django连接到Cassandra数据库?,python,django,cassandra,Python,Django,Cassandra,我有一个项目,我必须使用卡桑德拉数据库与Django一起开发。我查看了这些文档,但只有关于mysql、sklite和postgre数据库的信息,没有关于Cassandra的信息。我正在寻找连接Django和Cassandra的示例方法: 我知道我必须在setting.py文件中设置数据库配置: 但它抛出了一个错误: Error was: No module named django_cassandra.base 有人能帮我吗?Django目前不支持nosql作为后端。有一个很好的类似djang
Error was: No module named django_cassandra.base
有人能帮我吗?Django目前不支持nosql作为后端。有一个很好的类似django的ORM叫做cqlengine,它正在积极开发中,datastax团队表示他们正在与cqlengine人合作。虽然不能在settings.py中使用数据库defs,但可以使用类似django的命令,例如thingy.objects.all来访问您的cassandra datastax站点上的本机datastax python驱动程序更面向cqlsh,可能会让您想起oracle连接器,但速度要快一点 链接中推荐的答案非常旧
希望这有帮助。您可以在Django项目文件夹中的settings.py中使用此模式: 可能重复的
Error was: No module named django_cassandra.base
DATABASES = {
'default': {
'ENGINE': 'django_cassandra_engine', # Install this engine from https://pypi.org/project/django-cassandra-engine/
'NAME': 'yourkeyspace', # the keyspace was created at cassandra
'USER': 'user',
'PASSWORD': 'password',
'HOST': '127.0.0.1', # You can add your hosts here (use ,)
'OPTIONS': {
'replication': {
'strategy_class': 'SimpleStrategy', # or any strategy you need
'replication_factor': 1 # Depend on your decision
},
'connection': {
'consistency': ConsistencyLevel.ONE,
'lazy_connect': True,
'retry_connect': True,
'port': 9042, # default port
# You can add any connection options for cassandra.Cluster() here!
}
}
}
}