cassandra.InvalidRequest: code=2200 [无效查询] message="Keyspace '' 不存在"

mic*_*al 5 python cassandra cassandra-2.0

我正在尝试为 cassandra使用python 驱动程序, 但是当我在 python shell 中运行这三行时

from cassandra.cluster import Cluster
cluster = Cluster()
session = cluster.connect('demo')
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

cassandra.InvalidRequest: code=2200 [Invalid query] message="Keyspace 'demo' does not exist"
Run Code Online (Sandbox Code Playgroud)

pip冻结 说 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> 
Run Code Online (Sandbox Code Playgroud)

没有名为“演示”的密钥空间,但我只是在关注这两个教程,他们没有说任何关于预创建密钥空间的内容 http://planetcassandra.org/getting-started-with-cassandra-and-python/ http: //datastax.github.io/python-driver/getting_started.html

And*_*ert 5

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

要学习本教程,您应该已经有一个正在运行的 Cassandra 实例,并且已经完成了 10 分钟的演练:http : //www.PlanetCassandra.org/try-cassandra/

try-cassandra 页面有一个开发人员演练的链接(单击“开始开发人员演练”)。开发人员演练有一个创建“演示”键空间的步骤:

密钥空间可以包括操作元素,例如复制因子和数据中心意识。让我们创建一个名为“demo”的键空间。我们将包括复制策略类和因子;将在以后的教程中介绍的详细信息。

要创建键空间“演示”,请在 CQL shell 提示符下键入:

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));
Run Code Online (Sandbox Code Playgroud)

  • 很好的发现,安迪。我还认为他们没有包含“CREATE KEYSPACE”语句很奇怪。 (2认同)