Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to use python driver for cassandra but when I run these three lines in python shell

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

I get this error

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

pip freeze says cassandra-driver==2.5.0

I checked 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> 

there is no keyspace named 'demo' but I'm just following these two tutorials and they haven't said anything about pre creating keyspace http://planetcassandra.org/getting-started-with-cassandra-and-python/ http://datastax.github.io/python-driver/getting_started.html

like image 252
micheal Avatar asked Apr 07 '15 16:04

micheal


1 Answers

The instructions for creating the 'demo' keyspace are at a page linked from 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: http://www.PlanetCassandra.org/try-cassandra/

The try-cassandra page has a link for the developer walkthrough (click on "Start Developer Walkthrough"). The developer walk through has a step for creating the 'demo' keyspace:

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 };

To create the table

use demo;
CREATE TABLE users (
  firstname text,
  lastname text,
  age int,
  email text,
  city text,
PRIMARY KEY (lastname));
like image 69
Andy Tolbert Avatar answered Oct 20 '22 22:10

Andy Tolbert