I'm new to Graph database and using Neo4j database with neomodel library in Django application.
The settings are defined as
NEOMODEL_NEO4J_BOLT_URL = os.environ.get('NEO4J_BOLT_URL')
NEOMODEL_SIGNALS = True
NEOMODEL_FORCE_TIMEZONE = False
NEOMODEL_ENCRYPTED_CONNECTION = True
NEOMODEL_MAX_POOL_SIZE = 50
and the models.py file has the following model
class Person(StructuredNode):
SEXES = {
'm': 'Male',
'f': 'Female',
}
id = properties.UniqueIdProperty()
first_name = properties.StringProperty(unique_index=True, required=True, max_length=100)
gender = properties.StringProperty(choices=SEXES, required=True)
In Django shell python manage.py shell, creating a node as
>>> from family_tree.models import Person
>>> person = Person(first_name='Anuj', gender='m')
>>> person.save()
<Person: {'id': '572d0b8ff3a8402ba58c4a03cace78ba', 'first_name': 'Anuj', 'middle_name': None, 'last_name': None, 'gender': 'm', 'date_of_birth': None, 'date_of_death': None, 'created': datetime.datetime(2023, 6, 24, 7, 44, 26, 223871, tzinfo=<UTC>)}>
But the database explorer has no nodes in it.
Also refreshing node gives DoesNotExist exception
>>> person.refresh()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/neomodel/core.py", line 616, in refresh
raise self.__class__.DoesNotExist("Can't refresh non existent node")
neomodel.core.PersonDoesNotExist: (PersonDoesNotExist(...), "Can't refresh non existent node")

The problem is setting
idin your Person class. This is a special field that is set internally by neomodel.According to https://neomodel.readthedocs.io/en/latest/properties.html
All nodes in neo4j have an internal id (accessible by the ‘id’ property in neomodel) however these should not be used by an application. Neomodel provides the UniqueIdProperty to generate unique identifiers for nodes (with a unique index)
If you change your code to use
uid(or any other field name) instead ofidit will work.