Back

AppwriteException: document_invalid_structure, Invalid document structure: Missing required attribut

  • 0
  • Self Hosted
  • Flutter
  • Users
Tanish
22 Feb, 2024, 12:29

I was trying to make a chat app and encountered this error when I tried to use Server API to progmatically create collection if (collection.attributes.isEmpty) { await _defineDocument(collection.$id); } // Return the collection id return collection.$id; } Future<void> _defineDocument(String collectionId) async { // Defining attributes try { // You are free to choose your own key name. // But make to sure to replace those things in the model too. await database.createStringAttribute( databaseId: AppwriteConstants.databaseId, collectionId: collectionId, key: "sender_name", size: 255, xrequired: true); wrote similar code for other attributes as well

When I go to appwrite console, it does show that these attributes are created...but gives the error that the required attribute is missing (with the same name as you can see) [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: AppwriteException: document_invalid_structure, Invalid document structure: Missing required attribute "sender_name" (400)

TL;DR
Developers are encountering an "AppwriteException: document_invalid_structure" error when trying to add a document to a collection due to a missing required attribute called "sender_name." Despite creating the attributes in the Appwrite console, the error persists. Make sure the required attributes are correctly set in the code to avoid this issue.
Tanish
22 Feb, 2024, 12:45

if anyone's reading this pls try and help, i been stuck here for a lot of days

memoonlite
22 Feb, 2024, 12:58

Does this error occur when you try to add a document to the collection that is shown in the screenshot above? Or just by running the above code?

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