Notice: Undefined index: id_field_name in vendor/magento/module-ui/Component/Form.php on line 78

I found the answer a long ago but I guess forgot to share it so I'am updating it considering it might help someone.

So below is the solution :

All you have to do is add given code in your model collection file.

protected $_idFieldName = 'block_id'; // Set primary key of your table here..

For reference please check this file in core modules : /var/www/html/magento2/vendor/magento/module-cms/Model/ResourceModel/Block/Collection.php


Inside on your module

yourmodule/Model/Grid/DataProvider.php

You have to place this below getData() function

public function getData()
{
    if (isset($this->loadedData)) {
        return $this->loadedData;
    }
    $items = $this->collection->getItems();
    foreach ($items as $model) {
        $this->loadedData[$model->getId()] = $model->getData();
    }
    $data = $this->dataPersistor->get('your_module_variable');

    if (!empty($data)) {
        $model = $this->collection->getNewEmptyItem();
        $model->setData($data);
        $this->loadedData[$model->getId()] = $model->getData();
        $this->dataPersistor->clear('your_module_variable');
    }

    return $this->loadedData;
}