Back

Failed to create indexes for collection 'user_details': Unknown attribute: firstName

  • 0
  • Self Hosted
  • Databases
zjjt
11 Apr, 2024, 12:00

Hi everyone, i am using a python script in order to seed my database and so far i am able to do so but it fails on the index creation. I am running appwrite version 1.5.4 self hosted. However when it tries to create the indexes it fails with the following message :Failed to create indexes for collection 'user_details': Unknown attribute: firstName. Here is the code i use to create the indexes i even check that the attributes i require for the index exists # Create collection indexes for user_details try: user_details_collection = databases.get_collection( database_id=database_id, collection_id=collection_ids["user_details"] ) user_details_attributes = [ attr["key"] for attr in user_details_collection["attributes"] ] if ( "firstName" in user_details_attributes and "lastName" in user_details_attributes and not user_details_collection["indexes"] ): databases.create_index( database_id=database_id, collection_id=collection_id, key="nameIndex", type=IndexType.UNIQUE, attributes=["firstName", "lastName"], ) databases.create_index( database_id=database_id, collection_id=collection_id, key="dobIndex", type=IndexType.KEY, attributes=["dateOfBirth"], ) else: print( f"Cannot create indexes for collection '{collection}': Required attributes do not exist." ) except Exception as e: print(f"Failed to create indexes for collection 'user_details': {str(e)}") What do i do wrong ?

TL;DR
A developer is having trouble creating indexes for a collection in their self-hosted appwrite version 1.5.4 setup using a Python script. The error message "Failed to create indexes for collection 'user_details': Unknown attribute: firstName" indicates that the attribute "firstName" does not exist. The issue lies in the conditional check before creating the index, which should be corrected to only attempt index creation if all required attributes are present. To fix this, adjust the if statement to ensure all necessary attributes ("firstName", "lastName") exist before creating the indexes.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more