ArangoDB-Community / pyArango

Python Driver for ArangoDB with built-in validation
https://pyarango.readthedocs.io/en/latest/
Apache License 2.0
238 stars 90 forks source link

Cannot create graph: ValueError("'%s' is not a defined a Collection" % colName) #191

Open nsa32752 opened 4 years ago

nsa32752 commented 4 years ago

Hi, I'm trying to create graph using createGraph(name='', createCollections=), but value error raised.

The collection and relation were created like below:

from pyArango.connection import *
from pyArango.collection import *

def create_collection(table):
    conn = Connection(username="root", password="root")
    db = conn["_system"]
    if db.hasCollection(table):
        db[table].delete()
        db.reload()
    collec = db.createCollection(className='Collection', name=table)
    doc1 = collec.createDocument({"_key":table})
    doc1.save()

def create_relation(table, rel_name, relation):
    conn = Connection(username="root", password="root")

    db = conn["_system"]

    if db.hasCollection(rel_name):
        rel = db[rel_name]
    else:
        rel = db.createCollection(className='Edges', name=rel_name)

I didn't use follows:

class collection(Collection):
    _fields = {
        "name": Field()
    }

class relation(Edges):
    _fields = {
        "number": Field()
    }

Because the names of collections and relations are function parameter, the class could not be used as the example above. However I failed to create graph without using the class. Also, I want to use function parameter when I make a graph. Are there solutions for these?