编程语言
首页 > 编程语言> > python – cassandra.InvalidRequest:code = 2200 [无效查询] message =“Keyspace”不存在”

python – cassandra.InvalidRequest:code = 2200 [无效查询] message =“Keyspace”不存在”

作者:互联网

我正在尝试使用python driver for cassandra
但是当我在python shell中运行这三行时

from cassandra.cluster import Cluster
cluster = Cluster()
session = cluster.connect('demo')

我收到这个错误

cassandra.InvalidRequest: code=2200 [Invalid query] message="Keyspace 'demo' does not exist"

pip freeze说cassandra-driver == 2.5.0

我检查了cqlsh

Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 2.1.4 | CQL spec 3.2.0 | Native protocol v3]
Use HELP for help.
cqlsh> describe keyspaces

system_traces  system

cqlsh> 

没有名为’demo’的密钥空间,但我只是关注这两个教程,他们没有说过预先创建密钥空间
http://planetcassandra.org/getting-started-with-cassandra-and-python/
http://datastax.github.io/python-driver/getting_started.html

解决方法:

创建“演示”键空间的说明位于从http://planetcassandra.org/getting-started-with-cassandra-and-python/链接的页面:

To follow this tutorial, you should already have a running Cassandra instance, and have gone through the 10 minute walkthrough here: 07001

try-cassandra页面有一个开发人员演练的链接(单击“Start Developer Walkthrough”).开发人员通过步骤创建“demo”键空间:

The keyspace can include operational elements, such as replication factor and data center awareness. Let’s create a keyspace called “demo”. We will include replication strategy class and factor; details that will be covered in a future tutorial.

To create the keyspace “demo”, at the CQL shell prompt, type:

cqlsh> CREATE KEYSPACE demo WITH REPLICATION = { ‘class’ : ‘SimpleStrategy’, ‘replication_factor’ : 1 };

要创建表

use demo;
CREATE TABLE users (
  firstname text,
  lastname text,
  age int,
  email text,
  city text,
PRIMARY KEY (lastname));

标签:python,cassandra,cassandra-2-0
来源: https://codeday.me/bug/20190623/1274858.html